clear all
cd "../data/anes"
*do "anes 2004 cumulative infile.do"
*svyset VCF0006A [pweight=VCF0009A], vce(linearized)
use "anes_timeseries_cdf_stata_20220916.dta"
svyset VCF0006a [pweight=VCF0009z], vce(linearized)
capture rename VCF0006a VCF0006A
recode VCF0301 (0=.), generate(party)
recode VCF0803 (0 9=.), generate(libcons)
/*
// Computing directly
forvalues y=1972(2)2004 {
quietly corr party libcons if VCF0004==`y'
di "`y' " r(C)[1,2]
}
// Compare Pearson and Spearman correlations
forvalues y=1972(2)2004 {
quietly spearman party libcons if VCF0004==`y'
local s=r(rho)
quietly corr party libcons if VCF0004==`y'
local p=r(rho)
di "`y' `p' `s'"
}
forvalues y=2008(4)2020 {
quietly spearman party libcons if VCF0004==`y'
local s=r(rho)
quietly corr party libcons if VCF0004==`y'
local p=r(rho)
di "`y' `p' `s'"
}
*/
// Replication
rangestat (corr) party libcons, interval(VCF0004 0 0)
graph twoway line corr_x VCF0004 if 1972<=VCF0004 & VCF0004<=2004, connect(direct) xlabel(1972(4)2004) xmtick(1972(2)2004)
// Replication with a better scale
graph twoway line corr_x VCF0004 if 1972<=VCF0004 & VCF0004<=2004, connect(direct) xlabel(1972(4)2004) xmtick(1972(2)2004) ylabel(0(.5)1) ymtick(0(.1)1)
/*
// Check against direct computations
contract VCF0004 corr_x
browse
*/
// Extension
graph twoway line corr_x VCF0004 if 1972<=VCF0004, connect(direct) xlabel(1972(4)2020) xmtick(1972(2)2020) ylabel(0(.5)1) ymtick(0(.1)1)