From: <Saved by Windows Internet Explorer 7>
Subject: 
Date: Wed, 9 Dec 2009 11:39:08 -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_healtrans.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
clear;=20
set mem 300m;=09
set more 1 ; =20
drop _all;
program drop _all;
capture log close;
log using c:\research\hrs\wealth\healtrans.log, replace ;=20

use c:\research\hrs\wealth\dataprep2;

* this program generates both a               ;
* 2 year and a 1 year health transition matrix;

* separate program for the dead people (death.do);=20
drop if dead=3D=3D1;
*keep PI and lagged health around;
gen PIholder=3DPI;
gen lhealage=3Dlheal*age1;
gen maleage=3Dmale*age1;

*IMPORTANT:_20pg stands for gg (NOT 1-gg!!!!) for 20th percentile and =
_20pb stands for bb for 20th percentile;

program define genvals;
  local i =3D 70;
  while `i' &lt;=3D100 { ;
    * quietly sum g_20 if age =3D=3D `i';
 *   scalar _20pg`i' =3D r(mean);

	gen _20pg`i'=3D.;
	replace _20pg`i'=3D (1-g_20) if age=3D=3D`i';
	gen _20pb`i'=3D.;
	replace _20pb`i'=3Db_20 if age=3D=3D`i';
=09
	gen _40pg`i'=3D.;
	replace _40pg`i'=3D (1-g_40) if age=3D=3D`i';
	gen _40pb`i'=3D.;
	replace _40pb`i'=3Db_40 if age=3D=3D`i';



	gen _60pg`i'=3D.;
	replace _60pg`i'=3D (1-g_60) if age=3D=3D`i';
	gen _60pb`i'=3D.;
	replace _60pb`i'=3Db_60 if age=3D=3D`i';=09


	gen _80pg`i'=3D.;
	replace _80pg`i'=3D (1-g_80) if age=3D=3D`i';
	gen _80pb`i'=3D.;
	replace _80pb`i'=3Db_80 if age=3D=3D`i';

    local i =3D `i'+1;
*sum _*;
  } ;
end;


program define ONEyear;
sum _20pb*;
*  gen i =3D 70;
*  gen i2 =3D 71;

 gen prob20g =3D 1;
  gen prob40g =3D 1;
  gen prob60g =3D 1;
  gen prob80g =3D 1;

  gen prob20b =3D 1;
  gen prob40b =3D 1;
  gen prob60b =3D 1;
  gen prob80b =3D 1;

gen A=3D0;
gen B=3D0;
gen C=3D0;

  local i =3D 70;
  while `i' &lt;=3D100 { ;

	replace A=3D(2-_20pb`i' - _20pg`i');
	replace B=3D(2*_20pg`i'-2);
	replace C=3D1+(_20pb`i'*_20pb`i') - (_20pb`i' + _20pg`i' );=09

	replace prob20b=3D(-B+sqrt( (B*B) - 4*(A*C) ))/(2*A) if age=3D=3D`i';
	replace prob20g=3D((prob20b*prob20b)+1-prob20b-_20pb`i')/(1-prob20b) if =
age=3D=3D`i';


	replace A=3D(2-_40pb`i' - _40pg`i');
	replace B=3D(2*_40pg`i'-2);
	replace C=3D1+(_40pb`i'*_40pb`i') - (_40pb`i' + _40pg`i' );=09
	replace prob40b=3D(-B+sqrt( (B*B) - 4*(A*C) ))/(2*A) if age=3D=3D`i';
	replace prob40g=3D((prob40b*prob40b)+1-prob40b-_40pb`i')/(1-prob40b) if =
age=3D=3D`i';


	replace A=3D(2-_60pb`i' - _60pg`i');
	replace B=3D(2*_60pg`i'-2);
	replace C=3D1+(_60pb`i'*_60pb`i') - (_60pb`i' + _60pg`i' );=09
	replace prob60b=3D(-B+sqrt( (B*B) - 4*(A*C) ))/(2*A) if age=3D=3D`i';
	replace prob60g=3D((prob60b*prob60b)+1-prob60b-_60pb`i')/(1-prob60b) if =
age=3D=3D`i';

	replace A=3D(2-_80pb`i' - _80pg`i');
	replace B=3D(2*_80pg`i'-2);
	replace C=3D1+(_80pb`i'*_80pb`i') - (_80pb`i' + _80pg`i' );=09
	replace prob80b=3D(-B+sqrt( (B*B) - 4*(A*C) ))/(2*A) if age=3D=3D`i';
	replace prob80g=3D((prob80b*prob80b)+1-prob80b-_80pb`i')/(1-prob80b) if =
age=3D=3D`i';


    local i =3D `i' + 1;
  } ;
drop A B C;
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 ;
makedist;



program define genPIshift;
	version 3.1;
* now generate percentiles of the distribution;
	replace PI=3DPip1;
	makedist;
	gen bp1=3Dageshift+(PI*bPI1)+(PI2*bPI2)+(PIage*bPIage);
	gen ebp1=3Dexp(bp1);
	gen heal1=3Debp1/(1+ebp1);
	replace PI=3DPip2;
	makedist;
	gen bp2=3Dageshift+(PI*bPI1)+(PI2*bPI2)+(PIage*bPIage);
	gen ebp2=3Dexp(bp2);
	gen heal2=3Debp2/(1+ebp2);
	replace PI=3DPip3;
	makedist;
	gen bp3=3Dageshift+(PI*bPI1)+(PI2*bPI2)+(PIage*bPIage);
	gen ebp3=3Dexp(bp3);
	gen heal3=3Debp3/(1+ebp3);
	replace PI=3DPip4;
	makedist;
	gen bp4=3Dageshift+(PI*bPI1)+(PI2*bPI2)+(PIage*bPIage);
	gen ebp4=3Dexp(bp4);
	gen heal4=3Debp4/(1+ebp4);

	gen _20th_percentile=3Dheal1;
	gen _40th_percentile=3Dheal2;
	gen _60th_percentile=3Dheal3;
	gen _80th_percentile=3Dheal4;
	drop bp1 bp2 bp3 bp4 ebp1 ebp2 ebp3 ebp4 heal1 heal2 heal3 heal4; * =
drops intermediate output from genPIshift;
end;

**************ESTIMATION HERE ******************************;

logit heal age1 age2 age3 lheal lhealage PI PI2 PIage male maleage;

gen ageshift=3D_b[_cons]+(_b[age1]*age1)+(_b[age2]*age2) =
+(_b[age3]*age3);
gen ageshiftFINAL=3D_b[_cons]+(_b[age1]*age1)+(_b[age2]*age2) =
+(_b[age3]*age3);
gen healshift=3D_b[lheal]+_b[lhealage]*age1;
gen PIshift=3D_b[PI]+_b[PIage]*age1;
gen bPI1=3D_b[PI];
gen bPI2=3D_b[PI2];
gen bPIage=3D_b[PIage];
gen bmale=3D_b[male];
gen maleshift=3D_b[male]+_b[maleage]*age1;

*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\healtrans, replace;
drop if age&gt;100;

***********************************;
* GRAPHS                           ;
***********************************;

set scheme s1mono;

********** generate predicted transitions, WOMEN IN GOOD HEALTH;
genPIshift;
gen g_20=3D_20th_percentile;
gen g_40=3D_40th_percentile;
gen g_60=3D_60th_percentile;
gen g_80=3D_80th_percentile;

twoway connected _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age, ysc(r(0 .3)) ylabel(0(.1).3) msymbol(T S D O) =
lpattern(solid longdash shortdash longdash_dot) ti("Probability of Being =
in Bad Health, by Permanent Income Percentile,", size(medsmall) span  =
color(black)) subtitle("In Good Health 2 Years Ago, Women", =
size(medsmall) span color(black)) l1(Prob(health=3Dbad)) ytitle("") =
saving(healg, replace);

graph use healg.gph;
graph display, ysize(6) xsize(8.25);
*graph export c:\research\papers\wealth\healgw.eps, replace;
*graph export c:\research\papers\wealth\healgw.emf, replace;
drop _*;

********** generate predicted transitions, WOMEN IN BAD HEALTH;
replace ageshift=3Dageshift+healshift;
genPIshift;
replace ageshift=3Dageshift-healshift;
gen b_20=3D_20th_percentile;
gen b_40=3D_40th_percentile;
gen b_60=3D_60th_percentile;
gen b_80=3D_80th_percentile;

genvals;
ONEyear;

twoway connected _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age, legend(off) ysc(r(0.7 .95)) ylabel(0.7(.1).95) =
msymbol(T S D O) lpattern(solid longdash shortdash longdash_dot) =
ti("Probability of Being in Bad Health, by Permanent Income =
Percentile,", size(medsmall) span color(black)) subtitle("In Bad Health =
2 Years Ago, Women", siz(medsmall) span color(black)) =
l1(Prob(health=3Dbad)) ytitle("") saving(healb, replace);
graph use healb.gph;
graph display, ysize(6) xsize(8.25);
*graph export c:\research\papers\wealth\healbw.eps, replace;
*graph export c:\research\papers\wealth\healbw.emf, replace;
**********numbers behind the graphs****************;
sort age;
by age: sum _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age;


sort age;
by age: sum prob*;

*ONE YEAR GRAPHS;

drop _*;

gen _20th_percentile =3D 1-prob20g;
gen _40th_percentile =3D 1-prob40g;
gen _60th_percentile =3D 1-prob60g;
gen _80th_percentile =3D 1-prob80g;
twoway connected _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age, ysc(r(0 .3)) ylabel(0(.1).3) msymbol(T S D O) =
lpattern(solid longdash shortdash longdash_dot) ti("Probability of Being =
in Bad Health, by Permanent Income Percentile,", size(medsmall) span =
color(black)) subtitle("In Good Health 1 Year Ago, Women", siz(medsmall) =
span color(black)) l1(Prob(health=3Dbad)) ytitle("") saving(healg1, =
replace);
graph use healg1.gph;
graph display, ysize(6) xsize(8.25);
graph export c:\research\papers\wealth\healgw1.eps, replace;
graph export c:\research\papers\wealth\healgw1.emf, replace;
**********numbers behind the graphs****************;
sort age;
by age: sum _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age;
drop _*;


gen _20th_percentile =3D prob20b;
gen _40th_percentile =3D prob40b;
gen _60th_percentile =3D prob60b;
gen _80th_percentile =3D prob80b;
twoway connected _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age, legend(off) ysc(r(0.7 .95)) ylabel(0.7(.1).95) =
msymbol(T S D O) lpattern(solid longdash shortdash longdash_dot)  =
ti("Probability of Being in Bad Health, by Permanent Income =
Percentile,", size(medsmall) span color(black)) subtitle("In Bad Health =
1 Year Ago, Women", siz(medsmall) span color(black)) =
l1(Prob(health=3Dbad)) ytitle("") saving(healb1, replace);
graph use healb1.gph;
graph display, ysize(6) xsize(8.25);
graph export c:\research\papers\wealth\healbw1.eps, replace;
graph export c:\research\papers\wealth\healbw1.emf, replace;
**********numbers behind the graphs****************;
sort age;
by age: sum _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age;


drop _*;

drop g_* b_* prob*;

*end;

********** generate predicted transitions, MEN IN GOOD HEALTH;


replace ageshift=3Dageshift+maleshift;
genPIshift;
replace ageshift=3Dageshift-maleshift;
gen g_20=3D_20th_percentile;
gen g_40=3D_40th_percentile;
gen g_60=3D_60th_percentile;
gen g_80=3D_80th_percentile;


twoway connected _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age, legend(off) ysc(r(0 .3)) ylabel(0(.1).3) msymbol(T =
S D O) lpattern(solid longdash shortdash longdash_dot)  ti("Probability =
of Being in Bad Health, by Permanent Income Percentile,", size(medsmall) =
span color(black)) subtitle("In Good Health 2 Years Ago, Men", =
size(medsmall) span color(black)) l1(Prob(health=3Dbad)) ytitle("") =
saving(healgm, replace);
graph use healgm.gph;
graph display, ysize(6) xsize(8.25);
*graph export c:\research\papers\wealth\healgm.eps, replace;=20
*graph export c:\research\papers\wealth\healgm.emf, replace;
**********numbers behind the graphs****************;
sort age;
by age: sum _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age;
drop _*;



********** generate predicted transitions, MEN IN BAD HEALTH;



replace ageshift=3Dageshift+maleshift+healshift;
genPIshift;
replace ageshift=3Dageshift-maleshift-healshift;

gen b_20=3D_20th_percentile;
gen b_40=3D_40th_percentile;
gen b_60=3D_60th_percentile;
gen b_80=3D_80th_percentile;

genvals;
ONEyear;

twoway connected _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age, legend(off) ysc(r(0.7 .95)) ylabel(0.7(.1).95) =
msymbol(T S D O) lpattern(solid longdash shortdash longdash_dot) =
ti("Probability of Being in Bad Health, by Permanent Income =
Percentile,", size(medsmall) span color(black)) subtitle("In Bad Health =
2 Years Ago, Men", size(medsmall) span color(black)) =
l1(Prob(health=3Dbad)) ytitle("") saving(healbm, replace);
graph use healbm.gph;
graph display, ysize(6) xsize(8.25);
*graph export c:\research\papers\wealth\healbm.eps, replace;
*graph export c:\research\papers\wealth\healbm.emf, replace;
**********numbers behind the graphs****************;
sort age;
by age: sum _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age;
sort age;
by age: sum prob*;

*ONE YEAR GRAPHS;

drop _*;

gen _20th_percentile =3D 1-prob20g;
gen _40th_percentile =3D 1-prob40g;
gen _60th_percentile =3D 1-prob60g;
gen _80th_percentile =3D 1-prob80g;
twoway connected _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age, legend(off) ysc(r(0 .3)) ylabel(0(.1).3) msymbol(T =
S D O) lpattern(solid longdash shortdash longdash_dot) ti("Probability =
of Being in Bad Health, by Permanent Income Percentile,", size(medsmall) =
span color(black)) subtitle("In Good Health 1 Year Ago, Men", =
siz(medsmall) span color(black)) l1(Prob(health=3Dbad)) ytitle("") =
saving(healgm1, replace);
graph use healgm1.gph;
graph display, ysize(6) xsize(8.25);
graph export c:\research\papers\wealth\healgm1.eps, replace;
graph export c:\research\papers\wealth\healgm1.emf, replace;
**********numbers behind the graphs****************;
sort age;
by age: sum _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age;
drop _*;


gen _20th_percentile =3D prob20b;
gen _40th_percentile =3D prob40b;
gen _60th_percentile =3D prob60b;
gen _80th_percentile =3D prob80b;
twoway connected _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age, legend(off) ysc(r(0.7 .95)) ylabel(0.7(.1).95) =
msymbol(T S D O) lpattern(solid longdash shortdash longdash_dot) =
ti("Probability of Being in Bad Health, by Permanent Income =
Percentile,", size(medsmall) span color(black)) subtitle("In Bad Health =
1 Year Ago, Men", siz(medsmall) span color(black)) =
l1(Prob(health=3Dbad)) ytitle("") saving(healbm1, replace);
graph use healbm1.gph;
graph display, ysize(6) xsize(8.25);
graph export c:\research\papers\wealth\healbm1.eps, replace;
graph export c:\research\papers\wealth\healbm1.emf, replace;
**********numbers behind the graphs****************;
sort age;
by age: sum _20th_percentile _40th_percentile _60th_percentile =
_80th_percentile age;
drop _*;

drop g_* b_* prob*;

use c:\research\hrs\wealth\healtrans, replace;


keep age1 ageshiftFINAL healshift maleshift PIshift bPI2;
order age1 ageshiftFINAL healshift maleshift PIshift bPI2;

outsheet using c:\research\hrs\wealth\healthprof,nonames replace;

drop _all;
program drop _all;
log close;
</PRE></BODY></HTML>
