From: <Saved by Windows Internet Explorer 7>
Subject: 
Date: Thu, 10 Dec 2009 13:41:01 -0600
MIME-Version: 1.0
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.chicagofed.org/economic_research_and_data/research_resources/files/rr_french_medexFE_res.do
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 6.00.6000.16915" name=3DGENERATOR></HEAD>
<BODY><PRE># delimit ;=20

************************************ FE*****************************;

clear;=20
set mem 300m;=09
set more 1 ; =20
drop _all;
program drop _all;
capture log close;
log using c:\research\hrs\wealth\medex.log, replace ;=20

*----------------programs here----------------------------;
*---------------------------------------------------------;
program define fixresid;
			reg res b22-b40 ag11-ag65
ab11-ab66;

predict predres;

fixcoh;
summ predres;
predict meanres; summ predres meanres res;
end;

program define fixcoh;
	version 3.1;
		local i =3D 22;
		while `i' &lt;=3D40{;
		replace b`i'=3D0;
		local i=3D`i'+1 };

replace b40=3D1;

fixabag;
end;

*this program generates a polynomial in adist;
program define genPIshift;
        version 3.1;
	replace PI=3DPip1;
	makedist;
	gen lmedcostp1=3Dageshiftvarc+PI*bPI+PI2*bPI2+(PIage*bPIage);
	replace lmedcostp1=3Dlmedcostp1+(vage+ PI*bvPI+ PI2*bvPI2  =
+PIage*bvPIage )/2;
	replace PI=3DPip2;
	makedist;
	gen lmedcostp2=3Dageshiftvarc+PI*bPI+PI2*bPI2+(PIage*bPIage);
	replace lmedcostp2=3Dlmedcostp2+(vage+ PI*bvPI+ PI2*bvPI2  =
+PIage*bvPIage )/2;
	replace PI=3DPip3;
	makedist;
	gen lmedcostp3=3Dageshiftvarc+PI*bPI+PI2*bPI2+(PIage*bPIage);
	replace lmedcostp3=3Dlmedcostp3+(vage+ PI*bvPI+ PI2*bvPI2  =
+PIage*bvPIage )/2;
	replace PI=3DPip4;
	makedist;
	gen lmedcostp4=3Dageshiftvarc+PI*bPI+PI2*bPI2+(PIage*bPIage);
	replace lmedcostp4=3Dlmedcostp4+(vage+ PI*bvPI+ PI2*bvPI2  =
+PIage*bvPIage )/2;

	gen _20th_percentile=3Dexp(lmedcostp1);
	gen _40th_percentile=3Dexp(lmedcostp2);
	gen _60th_percentile=3Dexp(lmedcostp3);
	gen _80th_percentile=3Dexp(lmedcostp4);
drop lmedcostp*;
end;

*this program generates a polynomial in adist;
program define makedist;
        version 3.1;
	drop PI2 PI3 PIage;
	gen PI2=3DPI*PI;
	gen PI3=3D PI2*PI;
	gen PIage=3DPI*age1;
end;
set trace off ;

*------------------------------------------------------------;


use c:\research\hrs\wealth\dataprep2;

gen cohort8=3D0;
replace cohort8=3D1 if cohort=3D=3D.;
replace cohort=3D8 if cohort8=3D=3D1;

replace medcost=3Drmedcost;
replace medcost=3D. if wave&lt;3;
*drop if wave&lt;3;
*drop if wave&gt;7;
replace medcost=3D250 if medcost&lt;250;

* log medcost;
gen lmedcost=3Dln(medcost);
*drop if lmedcost=3D=3D.;
replace heal=3D1 if dead=3D=3D1; * in dataprep2 i do this if =
died=3D=3D1.  changing it to "if dead=3D=3D1" gets at medical expenses =
of those who died in previous waves;
drop if heal=3D=3D.; * drops 3 obs;
sum *medc* PI male heal age1;


sort age1;
by age1: sum medcost lmedcost;

gen healage=3Dheal*age1;
*gen PIage=3Dheal*age1;
gen maleage=3Dmale*age1;


* drop married women;
sort HHID female realyear;
drop if HHID=3D=3DHHID[_n-1] &amp; realyear=3D=3Drealyear[_n-1];

sort wave;
by wave: sum age1 dead medcost;

makedist;


* OLS VERSUS FIXED EFFECTS;
* OLS is not consistent with what JOHN, Cristina and I have decided =
on--it is only descriptive;
if FE=3D=3D0{;
reg lmedcost age1 age2 age3  heal healage maleage PIage;

reg lmedcost age1 age2 age3  heal healage maleage PIage PI PI2 male;
gen  ageshiftOLS=3D_b[_cons]+(_b[age1]*age1)+(_b[age2]*age2) =
+(_b[age3]*age3);
sort age1;
by age1: sum ageshift*;
};

if FE=3D=3D1{;
* fixed effects ;
*xtreg lmedcost age1 age2 age3 age4 age5, fe i(HHID);
*xtreg lmedcost age1 age2 age3 age4 age5 heal, fe i(HHID);

xtreg lmedcost age1 age2 age3 age4 heal healage maleage PIage , fe =
i(HHID);

predict lmedcostp;
* get predictions;

gen ageshift=3D_b[_cons]+(_b[age1]*age1)+(_b[age2]*age2) =
+(_b[age3]*age3) +(_b[age4]*age4) ;
gen healshift=3D_b[heal]+_b[healage]*age1;
gen maleshift=3D_b[maleage]*age1;
gen PIshift=3D_b[PIage]*age1;
gen bPIage=3D_b[PIage];

drop lmedcostp;
gen lmedcostp=3Dageshift+(healshift*heal)+(maleshift*male)+(PIshift*PI);
gen lmedcostres=3Dlmedcost-lmedcostp;



*sum lmedcost*;
* now run an OLS regression on the residuals;
reg lmedcostres PI PI2 male cohort2 cohort3 cohort4 cohort6 cohort7 =
cohort8;
predict respred;
* set cohort dummies to 0;
replace cohort2=3D0;
replace cohort3=3D0;
replace cohort4=3D0;
replace cohort6=3D0;
replace cohort7=3D0;
replace cohort8=3D0;
predict meanres;
gen lmedcadj=3Dlmedcost+meanres-respred;
gen medcadj=3Dexp(lmedcadj);

save C:\research\hrs\wealth\medresid, replace;

gen b=3D_b[_cons];
replace ageshift=3Dageshift+_b[_cons];
gen ageshiftFINAL=3Dageshift;
gen bPI =3D_b[PI];
gen bPI2=3D_b[PI2];
gen bmale=3D_b[male];
replace maleshift=3Dmaleshift+_b[male];
replace PIshift=3DPIshift+_b[PI]; * do not add in quadratic term, as we =
keep track of that separately;
* see if cohort effects are important to worry about (as it turns out, =
they are);


* figure out variance of residual;
gen resres=3Dlmedcostres-respred;
*drop if resres=3D=3D.;
egen sdres=3Dsd(resres);
gen varc=3D(sdres*sdres);

* figure out the unconditional variance;
egen sdmedc=3Dsd(lmedcost);
gen varcmed=3Dsdmedc*sdmedc;

* R2 measure;
gen R2meas=3D1-varc/varcmed;

gen varc2=3Dlmedcostres*lmedcostres;
gen varc1=3Dresres*resres;
reg varc1;
reg varc1 age1 ;
reg varc1 age1 age2 male heal PI;



*xtreg varc1 age1 age2 age3 heal healage PIage, fe i(HHID);
*gen vageFE=3D_b[_cons]+(_b[age1]*age1)+(_b[age2]*age2) =
+(_b[age3]*age3);




reg varc1 age1 age2 age3 age4 male maleage heal healage PI PI2 PIage ;
* reg varc1 age1 age2 age3 male maleage heal healage PI PI2 PIage =
cohort2 cohort3 cohort4  cohort6 cohort7 cohort8;
predict varc1p;


*exit;

gen vage=3D_b[_cons]+(_b[age1]*age1)+(_b[age2]*age2) +(_b[age3]*age3) =
+(_b[age4]*age4);





* gen vage=3D_b[_cons]+(_b[age1]*age1);
gen vmale=3D_b[male]+(_b[maleage]*age1);
*gen vmale=3D0;
gen vheal=3D_b[heal]+(_b[healage]*age1);
gen vPI=3D_b[PI]+(_b[PIage]*age1);
gen vPI2=3D_b[PI2];

gen bvPI=3D_b[PI];
gen bvPIage=3D_b[PIage];
gen bvPI2=3D_b[PI2];


* sort age1;
* by age1: sum vage*;
*two conn vage vageFE age1;

sum varc* R2meas;



gen ageshiftvarc=3Dageshift;

* gen medcostp=3Dexp(lmedcostp); * this term is meaningless, in the =
aggregate;
};


*rename age1 age;
sort age HHID;

drop if age&gt;102|age&lt;70;
drop if age=3D=3Dage[_n-1];
save c:\research\hrs\wealth\medexprof, replace;
drop if age&gt;100;

***********************************;
* GRAPHS                           ;
***********************************;

set scheme s1mono;

* WOMEN, GOOD HEALTH;

*In order to take off a blue or pink background delete =
"plotregion(ifcolor(pink*0.08))" in a line below;

genPIshift;
twoway connected _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age, ylabel(0(10000)50000) msymbol(T S D O) =
lpattern(solid longdash shortdash longdash_dot) ti("Medical Expenses, by =
Permanent Income Percentile, Women in Good Health", size(medsmall)) =
l1(1998 dollars) ytitle("") saving(medex, replace);
graph use medex.gph;
graph display, ysize(6) xsize(8.25);
graph export c:\research\papers\wealth\medexgw.eps, replace;
graph export c:\research\papers\wealth\medexgw.emf, replace;
**********numbers behind the graphs****************;
sort age;
by age: sum _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age;
drop _*;

* WOMEN, BAD HEALTH;

replace ageshiftvarc =3Dageshiftvarc+healshift+vheal/2;
genPIshift;
replace ageshiftvarc =3Dageshiftvarc-healshift-vheal/2;

twoway connected _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age, legend(off) ylabel(0(10000)50000) msymbol(T S D O) =
lpattern(solid longdash shortdash longdash_dot) ti("Medical Expenses, by =
Permanent Income Percentile, Women in Bad Health",size(medsmall)) =
l1(1998 dollars) ytitle("") saving(medex, replace);
graph use medex.gph;
graph display, ysize(6) xsize(8.25);
graph export c:\research\papers\wealth\medexbw.eps, replace;
graph export c:\research\papers\wealth\medexbw.emf, replace;
**********numbers behind the graphs****************;
sort age;
by age: sum _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age;
drop _*;

* MEN, GOOD HEALTH;

replace ageshiftvarc =3Dageshiftvarc+maleshift+vmale/2;
genPIshift;
replace ageshiftvarc =3Dageshiftvarc-maleshift-vmale/2;

twoway connected _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age, legend(off) ylabel(0(10000)50000) msymbol(T S D O) =
lpattern(solid longdash shortdash longdash_dot) ti("Medical Expenses, by =
Permanent Income Percentile, Men in Good Health", size(medsmall)) =
l1(1998 dollars) ytitle("") saving(medex, replace);
graph use medex.gph;
graph display, ysize(6) xsize(8.25);
graph export c:\research\papers\wealth\medexgm.eps, replace;
graph export c:\research\papers\wealth\medexgm.emf, replace;
**********numbers behind the graphs****************;
sort age;
by age: sum _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age;
drop _*;

* MEN, BAD HEALTH;

replace ageshiftvarc =
=3Dageshiftvarc+maleshift+healshift+vheal/2+vmale/2;
genPIshift;
replace ageshiftvarc =
=3Dageshiftvarc-maleshift-healshift-vheal/2-vmale/2;

twoway connected _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age, legend(off) ylabel(0(10000)50000) msymbol(T S D O) =
lpattern(solid longdash shortdash longdash_dot) ti("Medical Expenses, by =
Permanent Income Percentile, Men in Bad Health", size(medsmall)) l1(1998 =
dollars) ytitle("") saving(medex, replace);
graph use medex.gph;
graph display, ysize(6) xsize(8.25);
graph export c:\research\papers\wealth\medexbm.eps, replace;
graph export c:\research\papers\wealth\medexbm.emf, replace;
**********numbers behind the graphs****************;
sort age;
by age: sum _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age;

use c:\research\hrs\wealth\medexprof, replace;


keep age ageshiftFINAL healshift maleshift PIshift bPI2 vage vheal vmale =
vPI vPI2;
order age ageshiftFINAL healshift maleshift PIshift bPI2 vage vheal =
vmale vPI vPI2;

sum;

outsheet using c:\research\hrs\wealth\medexprof,nonames replace;
drop _all;
program drop _all;
log close;
</PRE></BODY></HTML>
