I have two cross-sectional datasets (year1 and Year 20) that I have pooled. My aim is to compute concentration indices and contributions for each of the dataset and then calculate the difference between the concentration indices and contributions calculated for the two periods.
I used the if command to keep data for year 1 and calculated quantities and stored them in sclars. Thereafter, I executed the clear command, drop my program and then called the pooled data and kept the Year 20 using the if command. I realised that at the end of calculating my quantities for year 20 it seems the scalars for year 1 are not stored. I have reproduced a section of my program here for help:
clear
set memory 300m
/* Computations of Quantities for 2003 */
use "/Users/gordonabekah-nkrumah/Documents/Document General/Main Documents/Latest Buckup 29 JAn/Academic Documents/WIP and Project papers/Institutional Projects/University of Ghana/Inequality In Child Nutrition in Ghana/Data/Ghana_Pro_03-2014.DTA"
keep if year==2003
/* Computation of Concentration Index of Y */
gen weight12=sample_weight
replace weight12=weight12*10^6
replace weight12= int(sample_weight)
tempvar rank wi sumwi wj rk
gen n = _N
egen rank = rank(wealth_transfmed), unique
sort rank
gen wi = 1/n
gen sumwi = sum(wi)
gen wj = sumwi[_n-1]
replace wj = 0 if wj ==.
gen rk = wj + 0.5*wi
qui sum neghaz [fw=weight12]
scalar mean1= r(mean)
qui cor rk neghaz [fw=weight12], c
sca var1=r(cov_12)
sca ciy01= (2/mean1)*var1
sca list ciy01
/* Decomposition of Concentration Index */
capture program drop myboot4, rclass
program define myboot4
qui xi:reg haz_who i.chld_age_mth1 i.sex_child i.size_birth i.educat_level i.ptner_educ_level i.gender_hh numb_u5_child numb_elig_women women_height wealth_transfmed i.eco_zone1 i.rural_resid netwk_gwater2 netwk_gtoilet2 netwk_vaccp2 netwk_assist_12p2 i.year, vce(cluster hh_numb)
/* mean values */
qui sum neghaz [fw=weight12]
scalar my = r(mean)
qui sum _Ichld_age__2
scalar m01=r(mean)
qui sum _Ichld_age__3
scalar m02=r(mean)
qui sum _Ichld_age__4
scalar m03=r(mean)
/* Regression Coefficients */
sca b01 = _b[_Ichld_age__2]
sca b02 = _b[_Ichld_age__3]
sca b03 = _b[_Ichld_age__4]
/* Computations of Elasticities */
sca e01 =(b01*m01)/my
sca e02 =(b02*m02)/my
sca e03 =(b03*m03)/my
/* concentration indices */
corr rk neghaz , c
sca ciy = 2*r(cov_12)/my
corr rk _Ichld_age__2 , c
sca ci01 = 2*r(cov_12)/m01
corr rk _Ichld_age__3 , c
sca ci02 = 2*r(cov_12)/m02
/* contribution from variables in numbers */
sca c01 = b01*m01*ci01/(my*ciy)
sca c02 = b02*m02*ci02/(my*ciy)
sca c03 = b03*m03*ci03/(my*ciy)
/* contributions from variables in percentage of predicted CI */
sca cp01 = 100*b01*m01*ci01/(my*ciy)
sca cp02 = 100*b02*m02*ci02/(my*ciy)
sca cp03 = 100*b03*m03*ci03/(my*ciy)
end
bootstrap ciy ci01 ci02 ci03
clear
pr drop myboot4
use "/Users/gordonabekah-nkrumah/Documents/Document General/Main Documents/Latest Buckup 29 JAn/Academic Documents/WIP and Project papers/Institutional Projects/University of Ghana/Inequality In Child Nutrition in Ghana/Data/Ghana_Pro_03-2014.DTA"
keep if year==2014
gen weight12=sample_weight
replace weight12=weight12*10^6
replace weight12= int(sample_weight)
tempvar rank wi sumwi wj rk
gen n = _N
egen rank = rank(wealth_transfmed), unique
sort rank
gen wi = 1/n
gen sumwi = sum(wi)
gen wj = sumwi[_n-1]
replace wj = 0 if wj ==.
gen rk = wj + 0.5*wi
qui sum neghaz [fw=weight12]
scalar mean1= r(mean)
qui cor rk neghaz [fw=weight12], c
sca var1=r(cov_12)
sca ciy01_1= (2/mean1)*var1
sca list ciy01_1
capture program drop myboot4, rclass
program define myboot4
qui xi:reg haz_who i.chld_age_mth1 i.sex_child i.size_birth i.educat_level i.ptner_educ_level i.gender_hh numb_u5_child numb_elig_women women_height wealth_transfmed i.eco_zone1 i.rural_resid netwk_gwater2 netwk_gtoilet2 netwk_vaccp2 netwk_assist_12p2 i.year, vce(cluster hh_numb)
/* mean values */
qui sum neghaz [fw=weight12]
scalar my_1 = r(mean)
qui sum _Ichld_age__2
scalar m01_1=r(mean)
qui sum _Ichld_age__3
scalar m02_1=r(mean)
/* Regression Coefficients */
sca b01_1 = _b[_Ichld_age__2]
sca b02_1 = _b[_Ichld_age__3]
sca b03_1 = _b[_Ichld_age__4]
/* Computations of Elasticities */
sca e01_1 =(b01_1*m01_1)/my_1
sca e02_1 =(b02_1*m02_1)/my_1
sca e03_1 =(b03_1*m03_1)/my_1
/* concentration indices */
corr rk neghaz , c
sca ciy_1 = 2*r(cov_12)/my_1
corr rk _Ichld_age__2 , c
sca ci01_1 = 2*r(cov_12)/m01_1
corr rk _Ichld_age__3 , c
sca ci02_1 = 2*r(cov_12)/m02_1
/* Contributions from Variables in Numbers */
sca c01_1 = b01_1*m01_1*ci01_1/(my_1*ciy_1)
sca c02_1 = b02_1*m02_1*ci02_1/(my_1*ciy_1)
sca c03_1 = b03_1*m03_1*ci03_1/(my_1*ciy_1)
/* contributions from variables in percentage of predicted CI */
sca cp01_1 = 100*b01_1*m01_1*ci01_1/(my_1*ciy_1)
sca cp02_1 = 100*b02_1*m02_1*ci02_1/(my_1*ciy_1)
sca cp03_1 = 100*b03_1*m03_1*ci03_1/(my_1*ciy_1)
end
bootstrap ciy_1 ci01_1 ci02_1 ci03_1
* Decomposition of Change in Inequality - Oaxaca */
sca dc01 = e01_1*(ci01_1-ci01)+ci01*(e01_1-e01)
sca dc02 = e02_1*(ci02_1-ci02)+ci02*(e02_1-e02)
sca dc03 = e03_1*(ci03_1-ci03)+ci03*(e03_1-e03)
I used the if command to keep data for year 1 and calculated quantities and stored them in sclars. Thereafter, I executed the clear command, drop my program and then called the pooled data and kept the Year 20 using the if command. I realised that at the end of calculating my quantities for year 20 it seems the scalars for year 1 are not stored. I have reproduced a section of my program here for help:
clear
set memory 300m
/* Computations of Quantities for 2003 */
use "/Users/gordonabekah-nkrumah/Documents/Document General/Main Documents/Latest Buckup 29 JAn/Academic Documents/WIP and Project papers/Institutional Projects/University of Ghana/Inequality In Child Nutrition in Ghana/Data/Ghana_Pro_03-2014.DTA"
keep if year==2003
/* Computation of Concentration Index of Y */
gen weight12=sample_weight
replace weight12=weight12*10^6
replace weight12= int(sample_weight)
tempvar rank wi sumwi wj rk
gen n = _N
egen rank = rank(wealth_transfmed), unique
sort rank
gen wi = 1/n
gen sumwi = sum(wi)
gen wj = sumwi[_n-1]
replace wj = 0 if wj ==.
gen rk = wj + 0.5*wi
qui sum neghaz [fw=weight12]
scalar mean1= r(mean)
qui cor rk neghaz [fw=weight12], c
sca var1=r(cov_12)
sca ciy01= (2/mean1)*var1
sca list ciy01
/* Decomposition of Concentration Index */
capture program drop myboot4, rclass
program define myboot4
qui xi:reg haz_who i.chld_age_mth1 i.sex_child i.size_birth i.educat_level i.ptner_educ_level i.gender_hh numb_u5_child numb_elig_women women_height wealth_transfmed i.eco_zone1 i.rural_resid netwk_gwater2 netwk_gtoilet2 netwk_vaccp2 netwk_assist_12p2 i.year, vce(cluster hh_numb)
/* mean values */
qui sum neghaz [fw=weight12]
scalar my = r(mean)
qui sum _Ichld_age__2
scalar m01=r(mean)
qui sum _Ichld_age__3
scalar m02=r(mean)
qui sum _Ichld_age__4
scalar m03=r(mean)
/* Regression Coefficients */
sca b01 = _b[_Ichld_age__2]
sca b02 = _b[_Ichld_age__3]
sca b03 = _b[_Ichld_age__4]
/* Computations of Elasticities */
sca e01 =(b01*m01)/my
sca e02 =(b02*m02)/my
sca e03 =(b03*m03)/my
/* concentration indices */
corr rk neghaz , c
sca ciy = 2*r(cov_12)/my
corr rk _Ichld_age__2 , c
sca ci01 = 2*r(cov_12)/m01
corr rk _Ichld_age__3 , c
sca ci02 = 2*r(cov_12)/m02
/* contribution from variables in numbers */
sca c01 = b01*m01*ci01/(my*ciy)
sca c02 = b02*m02*ci02/(my*ciy)
sca c03 = b03*m03*ci03/(my*ciy)
/* contributions from variables in percentage of predicted CI */
sca cp01 = 100*b01*m01*ci01/(my*ciy)
sca cp02 = 100*b02*m02*ci02/(my*ciy)
sca cp03 = 100*b03*m03*ci03/(my*ciy)
end
bootstrap ciy ci01 ci02 ci03
clear
pr drop myboot4
use "/Users/gordonabekah-nkrumah/Documents/Document General/Main Documents/Latest Buckup 29 JAn/Academic Documents/WIP and Project papers/Institutional Projects/University of Ghana/Inequality In Child Nutrition in Ghana/Data/Ghana_Pro_03-2014.DTA"
keep if year==2014
gen weight12=sample_weight
replace weight12=weight12*10^6
replace weight12= int(sample_weight)
tempvar rank wi sumwi wj rk
gen n = _N
egen rank = rank(wealth_transfmed), unique
sort rank
gen wi = 1/n
gen sumwi = sum(wi)
gen wj = sumwi[_n-1]
replace wj = 0 if wj ==.
gen rk = wj + 0.5*wi
qui sum neghaz [fw=weight12]
scalar mean1= r(mean)
qui cor rk neghaz [fw=weight12], c
sca var1=r(cov_12)
sca ciy01_1= (2/mean1)*var1
sca list ciy01_1
capture program drop myboot4, rclass
program define myboot4
qui xi:reg haz_who i.chld_age_mth1 i.sex_child i.size_birth i.educat_level i.ptner_educ_level i.gender_hh numb_u5_child numb_elig_women women_height wealth_transfmed i.eco_zone1 i.rural_resid netwk_gwater2 netwk_gtoilet2 netwk_vaccp2 netwk_assist_12p2 i.year, vce(cluster hh_numb)
/* mean values */
qui sum neghaz [fw=weight12]
scalar my_1 = r(mean)
qui sum _Ichld_age__2
scalar m01_1=r(mean)
qui sum _Ichld_age__3
scalar m02_1=r(mean)
/* Regression Coefficients */
sca b01_1 = _b[_Ichld_age__2]
sca b02_1 = _b[_Ichld_age__3]
sca b03_1 = _b[_Ichld_age__4]
/* Computations of Elasticities */
sca e01_1 =(b01_1*m01_1)/my_1
sca e02_1 =(b02_1*m02_1)/my_1
sca e03_1 =(b03_1*m03_1)/my_1
/* concentration indices */
corr rk neghaz , c
sca ciy_1 = 2*r(cov_12)/my_1
corr rk _Ichld_age__2 , c
sca ci01_1 = 2*r(cov_12)/m01_1
corr rk _Ichld_age__3 , c
sca ci02_1 = 2*r(cov_12)/m02_1
/* Contributions from Variables in Numbers */
sca c01_1 = b01_1*m01_1*ci01_1/(my_1*ciy_1)
sca c02_1 = b02_1*m02_1*ci02_1/(my_1*ciy_1)
sca c03_1 = b03_1*m03_1*ci03_1/(my_1*ciy_1)
/* contributions from variables in percentage of predicted CI */
sca cp01_1 = 100*b01_1*m01_1*ci01_1/(my_1*ciy_1)
sca cp02_1 = 100*b02_1*m02_1*ci02_1/(my_1*ciy_1)
sca cp03_1 = 100*b03_1*m03_1*ci03_1/(my_1*ciy_1)
end
bootstrap ciy_1 ci01_1 ci02_1 ci03_1
* Decomposition of Change in Inequality - Oaxaca */
sca dc01 = e01_1*(ci01_1-ci01)+ci01*(e01_1-e01)
sca dc02 = e02_1*(ci02_1-ci02)+ci02*(e02_1-e02)
sca dc03 = e03_1*(ci03_1-ci03)+ci03*(e03_1-e03)
Comment