Skip to content

Commit

Permalink
Update Freedom House 2016, Prefix variable labels to avoid collision,…
Browse files Browse the repository at this point in the history
… Strip old dataset labels.
  • Loading branch information
mpearce committed Aug 3, 2016
1 parent 427fb9e commit 9cd1a15
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 11 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ UCIMerge requires STATA 13. The .csv files which link countries across datasets
## Currently Supported Datasets

* [Norris 2009](https://sites.google.com/site/pippanorris3/research/data#TOC-Democracy-Time-series-Data-Release-3.0-January-2009)
* [Freedom House 2015](https://freedomhouse.org/report/freedom-world/freedom-world-2015)
* [Freedom House 2016](https://freedomhouse.org/report/freedom-world/freedom-world-2015)
* [Polity IV](http://www.systemicpeace.org/polityproject.html)
* Polity IV Coups
* [World Development Indicators](http://data.worldbank.org)
* [KOF Index of Globalization](http://globalization.kof.ethz.ch)
* [The Lexical Index of Electoral Democracy (LIED)](http://ps.au.dk/forskning/forskningsprojekter/dedere/datasets/)
* [CIRI Human Rights Dataset](http://www.humanrightsdata.com)
* [Quality of Government Standard dataset](http://qog.pol.gu.se/data/datadownloads/qogstandarddata)
* [Cross National Time Series](http://www.databanksinternational.com)
* [Cross National Time Series](http://www.cntsdata.com)
* [Penn World Table version 8.1](http://www.rug.nl/research/ggdc/data/pwt/pwt-8.1)

You can add your own datasets by using one of these examples as a template.

## Structure and Philosophy

Intuitive directory structures and naming conventions means writing less code!
Expand All @@ -54,7 +56,7 @@ Intuitive directory structures and naming conventions means writing less code!
Please contribute! If you discover an error, please submit an issue on github or send a fix.

To contribute a new dataset:
* create a new merge .do file in the /lib directory. The fh.do is a well documented template.
* create a new merge .do file in the /lib directory. The polity.do is a well documented template.
* include the file in Master.do file
* update the UCIMergeList.csv with the new country code entries. Sort the merge list by the Source and UCINumeric fields.

Expand Down
33 changes: 33 additions & 0 deletions lib/begin.do
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ program define prefix
}
end

* Rename value labels
capture program drop prefix_var_labels
program define prefix_var_labels
display as text "`0'"
ds, has(vallabel)
local vars `r(varlist)'
foreach var of local vars {
local labname : value label `var'
label copy `labname' `0'_`labname', replace
label value `var' `0'_`labname'
}
labelbook, problems
la drop `r(notused)'
end


* Convenience method to create value lables from string variables
capture program drop encode_value_labels
program define encode_value_labels
Expand Down Expand Up @@ -59,6 +75,23 @@ program define use_or_import_source_excel
}
end


capture program drop use_or_import_source_csv
program define use_or_import_source_csv
args PREFIX URL
capture confirm file "source/`PREFIX'.dta"
if _rc!=0 {
noisily display "Importing `PREFIX' from web."
import delimited "`URL'", case(preserve) clear
compress
save "source/`PREFIX'.dta"
}
else {
use "source/`PREFIX'.dta", clear
}
end


capture program drop use_or_import_source
program define use_or_import_source
args PREFIX URL
Expand Down
1 change: 1 addition & 0 deletions lib/end.do
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
drop if year == .
notes drop _dta
label data

rename UCINumeric country
gen UCINumeric = country
Expand Down
22 changes: 14 additions & 8 deletions lib/fh.do
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
* 2015 Freedomhouse Freedom in the World Report
* https://freedomhouse.org/report/freedom-world/freedom-world-2015
* 2016 Freedomhouse Freedom in the World Report
* https://freedomhouse.org/report-types/freedom-world

* If no cached file in source/ go here:
local URL "http://mattpearce.name/files/fh2015.dta"
local URL "https://raw.githubusercontent.com/mpearce/FH/master/FH2016.csv"
* Prefix this source's variables with:
local PREFIX "fh"
* What is the year variable called in the source:
local YEARVAR "year"
* What is the country variable called in the source:
local COUNTRYVAR "country"
local COUNTRYVAR "UCINumeric"
* Which set of ids are used, matching "source" field in UCIMergeList:
local MERGEWITH "fh"
local MERGEWITH "UCI"
* In this example, the source already has a UCINumeric column.
* The "UCI" source is a replication of the UCICountries codes.

* Which field in UCIMergelist matches the country variable above (Name, Alpha or Numeric):
local MERGEUSING "Name"
local MERGEUSING "Numeric"

* Create the merge file to use with this source
tempfile merge
prep_mergefile `MERGEWITH' `MERGEUSING' `merge'

* If the file source file doesn't already exist then download and create it.
use_or_import_source `PREFIX' `URL'
use_or_import_source_csv `PREFIX' `URL'

* Do any transformations/recodes/corrections here

gen sum = cl + pr
label variable sum "Combined Civil Liberties and Political Rights score."

* Prefix the variables
prefix `PREFIX'

encode_value_labels fh_status

* Combine the merge file IDs with the current source
merge_ids `PREFIX' `YEARVAR' `COUNTRYVAR' `MERGEUSING' `merge'

drop `PREFIX'_UCINumeric

* Merge with the Dataset
merge_with_master
1 change: 1 addition & 0 deletions lib/norris.do
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This merge uses Refno accounting for the inconsistencies below. Refno may be not
*/

prefix `PREFIX'
prefix_var_labels `PREFIX'
merge_ids `PREFIX' `YEARVAR' `COUNTRYVAR' `MERGEUSING' `merge'

duplicates drop UCINumeric year, force
Expand Down
6 changes: 6 additions & 0 deletions lib/polity.do
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
* 2015 Polity 4
* http://www.systemicpeace.org/polity/polity4.htm

* If no cached file in source/ go here:
local URL "http://www.systemicpeace.org/inscr/p4v2015.xls"
* Prefix this source's variables with:
local PREFIX "polity"
* What is the year variable called in the source:
local YEARVAR "year"
* What is the country variable called in the source:
local COUNTRYVAR "ccode"
* Which set of ids are used, matching "source" field in UCIMergeList:
local MERGEWITH "Polity"
* Which field in UCIMergelist matches the country variable above (Name, Alpha or Numeric):
local MERGEUSING "Numeric"

tempfile merge
Expand Down
2 changes: 2 additions & 0 deletions lib/qog.do
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ ds ccode cname year ccodealp cname_year ccodealp_year ccodecow ccodewb version,
egen _tmp = rownonmiss(`r(varlist)'), s
drop if _tmp == 0
drop _tmp
label data

prefix `PREFIX'
prefix_var_labels `PREFIX'
merge_ids `PREFIX' `YEARVAR' `COUNTRYVAR' `MERGEUSING' `merge'

* Merge with the Dataset
Expand Down

0 comments on commit 9cd1a15

Please sign in to comment.