Re: Sex ratio at 2nd birth order [message #27354 is a reply to message #27351] |
Tue, 25 July 2023 13:04 |
Bridgette-DHS
Messages: 3199 Registered: February 2013
|
Senior Member |
|
|
Following is a response from Senior DHS staff member, Tom Pullum:
The following Stata program, which can be used with any IR file, calculates a new set of variables giving the sex of the child indexed by birth order rather than bidx (which is 1 for the most recent birth, etc.). It can be modified to be more general, if desired, to index any or all of the b variables by birth order rather than bidx.
use "...IAIR7EFL.DTA", clear
* Recode the b variables so they are indexed by bord rather than bidx
* Illustrated for just b4, sex of the child
* Based on the relationship bidx+bord=v201+1
rename *_0* *_*
* construct a new variable, sex, that is b4 indexed by bord rather than bidx
forvalues lceb=1/20 {
gen sex_`lceb'=.
quietly forvalues lbord=1/`lceb' {
local lbidx=`lceb'+1-`lbord'
replace sex_`lbord'=b4_`lbidx' if v201==`lceb'
}
}
tab1 sex_*
tab sex_2 sex_1 [iweight=v005/1000000],col
|
|
|