| | clear all
|
| | set more off
|
| | set maxvar 10000
|
| | set mem 500m
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | local procdata "./proc_data/"
|
| | local rawdata "./raw_data/"
|
| |
|
| | cd proc_data
|
| |
|
| |
|
| |
|
| | use cons1999.dta, clear
|
| | forval x=2001(2)2011{
|
| | append using cons`x'.dta
|
| | }
|
| |
|
| | sort hid year
|
| | xtset hid year
|
| |
|
| | save health_costs_for_income.dta, replace
|
| |
|
| |
|
| |
|
| |
|
| | use for_reg.dta, clear
|
| |
|
| | joinby hid year using health_costs_for_income.dta, unmatched(both)
|
| | tab _merge
|
| | drop if _merge!=3
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | local cpi1999 = 163.01
|
| | local cpi2001 = 172.19
|
| | local cpi2003 = 179.87
|
| | local cpi2005 = 188.91
|
| | local cpi2007 = 201.56
|
| | local cpi2009 = 215.25
|
| | local cpi2011 = 218.09
|
| | gen heal_cons_deflated=heal_cons
|
| | forval x=1999(2)2011{
|
| | replace heal_cons_deflated=heal_cons_deflated*(`cpi1999' / `cpi`x'') if year==`x'
|
| | }
|
| |
|
| |
|
| |
|
| | drop if inc<0
|
| |
|
| |
|
| | drop if year>2007
|
| | drop if age<25 & year==1999
|
| | drop if age>85 & year==2007
|
| | bys hid: gen nyear=[_N]
|
| | keep if nyear==5
|
| |
|
| |
|
| | gen a2=(age^2)/10
|
| |
|
| |
|
| | tab year, gen(time_dummy)
|
| |
|
| |
|
| | replace inc=log(inc)
|
| | keep inc time_dummy* age a2 hid year
|
| |
|
| |
|
| | gen retired=1 if age>=65
|
| | replace retired=0 if retired!=1
|
| |
|
| |
|
| | reg inc age a2 time_dummy* retired
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | estimates table, keep(age a2 retired) b
|
| |
|
| |
|
| |
|
| | predict inc_hat
|
| |
|
| |
|
| |
|
| | gen x_tilda=inc
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | replace year=1 if year==1999
|
| | replace year=2 if year==2001
|
| | replace year=3 if year==2003
|
| | replace year=4 if year==2005
|
| | replace year=5 if year==2007
|
| |
|
| | xtset hid year
|
| |
|
| |
|
| | bysort hid: egen mean_hid_inc=mean(inc)
|
| |
|
| | gen dif_mean=inc-mean_hid_inc
|
| |
|
| | sum dif_mean, d
|
| | gen p1=r(p1)
|
| | gen p99=r(p99)
|
| |
|
| | replace x_tilda=. if dif_mean<=p1
|
| | replace x_tilda=. if dif_mean>=p99
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | preserve
|
| |
|
| |
|
| | gen lag1_x_tilda=L.x_tilda
|
| | gen lag2_x_tilda=L2.x_tilda
|
| | gen lag3_x_tilda=L3.x_tilda
|
| | gen lag4_x_tilda=L4.x_tilda
|
| |
|
| |
|
| |
|
| | correlate x_tilda x_tilda, covariance
|
| | gen v0=r(Var_1)
|
| |
|
| | forval x=1(1)4{
|
| | correlate x_tilda lag`x'_x_tilda, covariance
|
| | g float v`x'=r(cov_12)
|
| | }
|
| | keep v*
|
| | duplicates drop
|
| |
|
| |
|
| |
|
| |
|
| | save autocov_final_new_NO_health_ALL_v3.dta, replace
|
| |
|
| |
|
| |
|
| | restore
|
| |
|
| | gen lag1_x_tilda=L.x_tilda
|
| | keep x_tilda lag1_x_tilda
|
| |
|
| | gen dif_x_tilda=x_tilda-lag1_x_tilda
|
| |
|
| | egen SD = sd(dif_x_tilda)
|
| |
|
| | egen KURT = kurt(dif_x_tilda)
|
| |
|
| | egen SKEW = skew(dif_x_tilda)
|
| |
|
| | keep SD KURT SKEW
|
| |
|
| |
|
| | duplicates drop
|
| |
|
| | merge using autocov_final_new_NO_health_ALL_v3.dta
|
| |
|
| | drop _merge
|
| |
|
| |
|
| | keep SD v0 v1 v2
|
| | replace SD = round(SD, 0.01)
|
| | replace v0 = round(v0, 0.01)
|
| | replace v1 = round(v1, 0.01)
|
| | replace v2 = round(v2, 0.01)
|
| |
|
| | order v0 v1 v2 SD
|
| |
|
| | cd ..
|
| |
|
| | cd output
|
| |
|
| | outsheet using tab2_income.csv, c replace
|
| |
|
| |
|