Using the database

Browsing large databases through point-and-click interfaces is more often than not a frustratingly slow process. I organised my database so that you can import the data you need through a few lines of code. In addition to being much faster, it also helps in the documentation of your data.

Stata code

All country-year variables are stored at http://paneldata.se/cy/. If you are working in a dataset with a country variable called id, which follows the numeric ISO 3166-1 standard, and a time variable called year, you can easily import any variable using Stata's merge command.

merge m:m id year using http://paneldata.se/cy/varname.dta, nogen

I have written a simple script that creates an empty dataset – containing only country codes – and writes a program called get. The program can then be used to merge variables with as little code as possible. Just type get followed by the names of the variables you want. Please note that the program clears the mata memory, which could bother some programmers. To run the script, just enter this line in Stata:

do http://www.paneldata.se/scripts/cy.do

Or copy and paste the following code:

use http://paneldata.se/cy/cy.dta, clear
tsset id year
expand 71
sort id year
replace year = year[_n-1] +1 if id == id[_n-1]

capture program drop get
program get
local importvars `*'
foreach x in `importvars' {
clear mata
merge m:m id year using http://paneldata.se/cy/`x'.dta, nogen keep(1 3)
}
sort id year
end