#delimit ; /* Means ; will indicate end of command, similar to matlab */
drop _all; /* Makes sure we don't have any var's in memory */
discard; /* Makes sure we haven't any stored locals, globals, or such in memory (overcourse for now) */
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Open data set from the web */
use http://www.nippelagerlof.com/teaching/5700/PWT_data_Sept2016_post2.dta, clear;
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Declare data set a panel data set */
xtset wb_ncode year, delta(10);
/* time veriable is year, panel variable is country (here identified by the numerical wb code) */
/* delta set to 10 meaning the lag/lead operators L. and F. goes ten years back */
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Generate new variables */
gen float pc_gdp=gdp/pop;
gen log_pc_gdp=log(pc_gdp);
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Generate growth rate variable */
gen growth=(F.log_pc_gdp - log_pc_gdp)/10;
/* Note use of lead operatir: for year==1960, growth rate refers to period 1960-1970 */
/* This is an approximation of the growth rate; how do we compute the exact value? */
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Label variables */
label var growth "Annual GDP/capita growth";
label var log_pc_gdp "Log GDP/capita";
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Create variable called pct, which indicates which percentile of some variable that observations belong to */
/* Here: 20 bins of population */
xtile pct = pop, n(20);
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Drop the 5% country-years with smallest population */
n drop if pct<=1;
/* n for noisily, means number obs dropped is reported in results window */
/* How would we drop the 10% smallest? */
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Plot growth 1960-70 against initial GDP/capita */
twoway(scatter growth log_pc_gdp if year==1960, msymbol(x) mcolor(red) mlabel(country_name) mlabsize(vsmall) );
/* Note: conditions written as == */
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Same as above with least-squares regression line */
twoway
(scatter growth log_pc_gdp if year==1960, msymbol(x) mcolor(red) mlabel(country_name) mlabsize(vsmall) )
(lfit growth log_pc_gdp if year==1960, ytitle(Annual GDP/capita growth) legend(off) );
/* Explain: Why do we add ytitle here? Why legend off/on ? How change to quadratic fit? */
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX */
/* Loop making many plots */
/* First set directory where plots are saved -- does not work with Citrix, it seems */
* cd "C:\Work\NewHomepage\Teaching\5700\PWT";
/* The loop */
foreach x in 1950 1960 1970 1980 1990 2000 { ; /* x is a so-called local; equals year that inital GDP/capita refers to */
local x_next=`x'+10; /* `x' to `x'+10 is the period; note the quotation marks around x */
twoway
(scatter growth log_pc_gdp if year==`x', msymbol(x) mcolor(red) mlabel(country_name) mlabsize(vsmall) )
(lfit growth log_pc_gdp if year==`x', ytitle(Growth `x'-`x_next') xtitle(Log GDP/capita `x') legend(off) title(`x'-`x_next') );
* graph save Graph "Growth_plot_`x'.gph", replace;
* graph export "Growth_plot_`x'.pdf", replace;
} ;
/* I have not been able to use graph save and graph export commands when working through Citrix,
could be problem with my account or settings */
/* Combining graphs: only works if able to save them */
/*
graph combine
"Growth_plot_1970.gph"
"Growth_plot_1980.gph" "Growth_plot_1990.gph"
"Growth_plot_2000.gph", ycommon xcommon cols(2);
*/