After a previous post on mapping the Political Ties with Stata, let me show how to compute how to create an idea point relatively a specific country. This reasoning can be applied to different types of variables.
The first step is to create a variable that will serve as a reference. Here, it will be the ideal point of China. Save temporarily the data for China using tempfile idealnew
. Don’t forget to run everything between preserve and restore. Then merge the ‘tempfile’ for China suing the temporal dimension and m:1 merge.
// Create a variable with a reference to specific country
preserve
keep if iso3=="CHN"
keep period_ idealnew
rename idealnew idealnewCHN
tempfile idealnew
save `idealnew'
restore
merge m:1 period_ using `idealnew'
drop _merge
Then, compute the distance to China and draw a graph. Here, I only used the data for the raw (non-smoothed) ideal points:
// Distance to China
xtset cn period_
xtdes
gen idealnewdistancetoCHN = idealnewCHN - idealnew ///
if idealnewCHN!=.
preserve
drop if period<=tm(1970m1)
keep if iso3=="USA" | iso3=="GBR" ///
| iso3=="CHN" | iso3=="DEU"
xtline idealnewdistancetoCHN, overlay legend(pos(6) cols(5)) ///
yline(0) ///
graphregion(margin(l+2 r+4)) ///
title(Ideal Distance to China Estimates: UN GA Voting Data)
graph rename Graph ideal_over_smoothed, replace
graph export figures\ideal_smoothed_overCHN.png, as(png) ///
width(4000) replace
graph export figures\ideal_smoothed_overCHN.pdf, as(pdf) ///
replace
restore
I am grateful to Andrew Musau for insightful answers on the Stata forum.
1 Comment
[…] Create a variable with a reference to a specific country Drawing Maps for Political Ties with Stata […]