STATA 11 for Windows SAMPLE SESSION - Food Security Group ...
STATA 11 for Windows SAMPLE SESSION - Food Security Group ...
STATA 11 for Windows SAMPLE SESSION - Food Security Group ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Stata <strong>11</strong> Sample Session Section 2 – Restructuring Data Files – Table Lookup & Aggregation<br />
save "hh-file1.dta", replace<br />
************************************<br />
*Step 2<br />
************************************<br />
/* calculating adult equivalents based on age and gender */<br />
use "c-q1a.dta", clear<br />
generate byte ae= 1 if ca4 == 1 & ca3 >=10<br />
replace ae = .84 if ca4==2 & ca3 >=10 & ca3 =20<br />
replace ae = .6 if ca3 < 10<br />
label variable ae "Adult equivalents"<br />
/* check the variable */<br />
tabulate ae, missing<br />
/* calculate mean to determine average ae across the whole population<br />
To fill in the missing values*/<br />
summarize ae<br />
/* replace all system missing with the value of .79 */<br />
replace ae = .79 if ae==.<br />
tabulate ae, missing<br />
/* need to sum the adult equivalents <strong>for</strong> each household */<br />
collapse (sum) ae, by(district vil hh)<br />
label variable ae "Adult equivalents per household"<br />
summarize ae<br />
* save file <strong>for</strong> later use */<br />
save "hh-file2.dta", replace<br />
************************************<br />
*Step 3<br />
************************************<br />
use "hh-file2.dta", clear<br />
/* now combine both the hh-file1 with hh-file2 , both files are already sorted by key variables<br />
match files by district vil hh */<br />
merge 1:1 district vil hh using "hh-file1.dta"<br />
*check to see which file the variables are coming from<br />
tab _merge<br />
*3 = variables came from both files<br />
drop _merge<br />
/* calculate the calories per adult equivalent per day */<br />
generate double cprod_ae= cprod_tt/ae/365<br />
label variable cprod_ae "Calories per adult equivalent per day"<br />
sum cprod_ae<br />
/* rank the new variable by district into quartiles<br />
84