***
*** Example 2.2. Decompositions into age, cohort, and year effects
***
*** The second example presents the code for the decomposition of earnings in
*** Taiwan (China) into age, cohort, and year effects; the methods are
**** discussed on pp. 116-27, and the results are shown in Figure 2.5.
***
*** Revised May 2003
***
*** Note: The following provides the STATA code used to produce
*** results used in "The Analysis of Household Surveys:
*** A Microeconometric Approach to Development Policy", by Angus Deaton.
*** This book, published for the World Bank by The Johns Hopkins University
*** Press and scheduled for release in 1997.
***
version 4.0
#delimit ;
set more 1;
drop _all;
use finp;
/*
**finp is a data set that is constructed from the
**original surveys from 1975-1990. For the individual
**level data, in each survey, the average earnings at
**each year is calculated, and this is saved, so that
**for each year from 1975 to 1990, finp contains age,
**average earnings of individuals of that age, and
**the survey year
**/
keep age yr iearn;
gen cohort=age-yr+65;
drop if age < 25;
drop if age > 65;
/* generating dummies for each age, cohort and year */
tab age, gen(aged);
tab cohort, gen(cohd);
tab yr, gen(yrd);
drop aged1;
drop cohd1;
/*
**constructing variables so that the year effects
**add to zero, and are orthogonal to a time trend */
replace yrd15=yrd15-14*yrd2+13*yrd1;
replace yrd14=yrd14-13*yrd2+12*yrd1;
replace yrd13=yrd13-12*yrd2+11*yrd1;
replace yrd12=yrd12-11*yrd2+10*yrd1;
replace yrd11=yrd11-10*yrd2+9*yrd1;
replace yrd10=yrd10-9*yrd2+8*yrd1;
replace yrd9=yrd9-8*yrd2+7*yrd1;
replace yrd8=yrd8-7*yrd2+6*yrd1;
replace yrd7=yrd7-6*yrd2+5*yrd1;
replace yrd6=yrd6-5*yrd2+4*yrd1;
replace yrd5=yrd5-4*yrd2+3*yrd1;
replace yrd4=yrd4-3*yrd2+2*yrd1;
replace yrd3=yrd3-2*yrd2+1*yrd1;
drop yrd2;
drop yrd1;
regress iearn aged* cohd* yrd*;
/* calculating & storing the year in variable yreff */
gen yreff=_b[yrd3] if yr==67;
replace yreff=_b[yrd4] if yr==68;
replace yreff=_b[yrd5] if yr==69;
replace yreff=_b[yrd6] if yr==70;
replace yreff=_b[yrd7] if yr==71;
replace yreff=_b[yrd8] if yr==72;
replace yreff=_b[yrd9] if yr==73;
replace yreff=_b[yrd10] if yr==74;
replace yreff=_b[yrd11] if yr==75;
replace yreff=_b[yrd12] if yr==76;
replace yreff=_b[yrd13] if yr==77;
replace yreff=_b[yrd14] if yr==78;
replace yreff=_b[yrd15] if yr==79;
global tem = -2*_b[yrd3]-3*_b[yrd4]-4*_b[yrd5]-5*_b[yrd6]-6*_b[yrd7]
-7*_b[yrd8]-8*_b[yrd9]-9*_b[yrd10]-10*_b[yrd11]-11*_b[yrd12]
-12*_b[yrd13]-13*_b[yrd14]-14*_b[yrd15];
replace yreff=$tem if yr==66;
global alpha1= -$tem-_b[yrd3]-_b[yrd4]-_b[yrd5]-_b[yrd6]-_b[yrd7]
-_b[yrd8]-_b[yrd9]-_b[yrd10]-_b[yrd11]-_b[yrd12]
-_b[yrd13]-_b[yrd14]-_b[yrd15];
replace yreff=$alpha1 if yr==65;
replace yr=yr+11;
/* calculating and storing cohort effects in coheff */
global nc=2;
global ic=12;
gen coheff=0 if cohort==11;
cap program drop doit;
program def doit;
while $ic < 66 {;
global ix="cohd$nc";
replace coheff=_b[$ix] if cohort==$ic;
global ic=$ic+1;
global nc=$nc+1;
};
end;
doit;
/* calculating and storing age effects */
mac def nc=2;
mac def ic=26;
gen ageff=0 if age==25;
cap program drop doit;
program def doit;
while $ic < 66 {;
mac def ix="aged$nc";
replace ageff=_b[$ix] if age==$ic;
mac def ic=$ic+1;
mac def nc=$nc+1;
};
end;
doit;
* Look at the results;
set more 0;
graph yreff yr, c(l) s(p) xlabel ylabel sort;
graph ageff age, c(l) s(.) xlabel ylabel sort;
graph coheff cohort, c(l) s(.) xlabel ylabel sort;
[Return to Program List]