Ratio of girls to boys in a family [message #16559] |
Fri, 25 January 2019 23:27 ![Go to next message Go to next message](/theme/default/images/down.png) |
sumonrupop
Messages: 23 Registered: August 2015 Location: Rajshahi
|
Member |
![sumon_khanru](/theme/default/images/skype.png)
|
|
Dear all,
Can anyone help me to calculate the ratio of girls to boys in a family? I found this should be calculated by using b2_01, b2_04, and b2_05 variables in IR file, but facing a problem when I tried to count male and female child.
Thanks in advance.
Sumon
Md. Nuruzzaman Khan
|
|
|
Re: Ratio of girls to boys in a family [message #16571 is a reply to message #16559] |
Tue, 29 January 2019 08:12 ![Go to previous message Go to previous message](/theme/default/images/up.png) |
Bridgette-DHS
Messages: 3143 Registered: February 2013
|
Senior Member |
|
|
Following is a response from Senior DHS Stata Specialist, Tom Pullum:
There are two ways to do this. The easy way is with the first two lines below. The second way is to loop through the b variables, as you were trying to do. The last three lines will confirm that you get the same results with both methods.
gen boys1=v202+v204+v206
gen girls1=v203+v205+v207
ren b*_0* b*_*
local li=1
while `li'<=20 {
gen boy_`li'=1 if b4_`li'==1
gen girl_`li'=1 if b4_`li'==2
local li=`li'+1
}
egen boys2=rowtotal(boy_*)
egen girls2=rowtotal(girl_*)
correlate boys*
correlate girls*
summarize boys* girls*
[Updated on: Tue, 29 January 2019 08:18] Report message to a moderator
|
|
|