************ * Tutorial * * ExampleC * ************ *** Two Variables Example (1 C-var, 1 index) *** ** Mean Value analysis (Baseline) ** * Loading the data clear use "C:\Users\fbizz\Dropbox\Dissertation\Data\vdem_cy_v5.dta" * Setting up the dataset xtset country_id year * Running the analysis with mean value xtreg F.e_peinfmor v2xel_frefair v2cldiscw e_migdppcln , fe vce(cluster country_id) * For a tutorial on how to create a working .dta file for the posteriors of those two variables, please refer to example A (v2cldiscw) and B (v2x_pubcorr) *** Incorporating Measurement Error *** *** Setting up Stata *** *Clears Data and Existing Matrices clear matrix drop _all *Changes Working Directory cd "C:\Users\fbizz\Dropbox\ShamrockSeries\Fernando\tutorial_CIs" /*INSERT THE DIRECTORY WHERE YOU EXTRACTED THE DATA FILES*/ * Loading posteriors dta * pubcorr use "frefair.dta", clear * Merge the second posterior merge m:m country_text_id country_id year using "C:\Users\fbizz\Dropbox\ShamrockSeries\Fernando\tutorial_CIs\cldiscw.dta", nogenerate * Merge with V-Dem Country-Year data merge m:m country_text_id year using "C:\Users\fbizz\Dropbox\Dissertation\Data\vdem_cy_v5.dta", nogenerate *Sets Data xtset country_id year * Set Matrix Size to fit analysis set matsize 5000 *** Analysis *** *** Monte Carlo Estimates Using V-Dem 900 Draw Posterior Distribution*** *Run the monte carlo forvalues i = 2/901 { *Print out an iteration number display `i' *Fit the model, using the ith draw from the UDS posterior quietly xtreg F.e_peinfmor frefair_v`i' cldiscw_v`i' e_migdppcln, fe vce(cluster country_id) *Extract the coefficients and variance-covariance matrix matrix b = e(b) matrix V = e(V) local blength = colsof(b) matrix rsq = e(r2) *Preserve the dataset, take a single multivariate normal draw from the *posterior distribution of the coefficients, and restore the dataset. *We use the capture command to catch possible errors in drawnorm *and drop these iterations gracefully. preserve capture quietly drawnorm b1-b`blength', double n(1) means(b) cov(V) clear if _rc==0 { mkmat b1-b`blength', matrix(bsample) matrix posterior = nullmat(posterior) \ bsample matrix rsquared = nullmat(rsquared) \ rsq } else { display "Error drawing sample...iteration dropped" } restore *Closes the Monte Carlo Loop } *Get posterior ready to work with svmat posterior svmat rsquared *Calculate means and standard deviations tabstat posterior*, stat(mean sd) *Find the bounds of the 95 percent credible interval centile posterior*, centile(2.5, 97.5) * Find the R-Squared tabstat rsquared*, stat(mean sd)