You need to
replace boyno = . if b != 1
Beyond that, you've lost me. Sorry,
Nick
[email protected]
Deepankar Basu
> Nick,
>
> Following your suggestion, I have -reshape- the data. This is how it
> looks now:
>
> id chilno dfsize nboy alive b boyno cno
> 1 1 4 2 4 1 1 1
> 1 2 4 2 4 2 1 2
> 1 3 4 2 4 1 2 3
> 1 4 4 2 4 2 2 4
> 1 5 4 2 4 . 2 4
> 1 6 4 2 4 . 2 4
> 1 7 4 2 4 . 2 4
> 2 1 4 2 3 1 1 1
> 2 2 4 2 3 . 1 1
> 2 3 4 2 3 2 1 2
> 2 4 4 2 3 . 1 2
> 2 5 4 2 3 1 2 3
> 2 6 4 2 3 . 2 3
> 2 7 4 2 3 . 2 3
>
>
> dfsize: desired family size
> nboy : number of boys alive in the family
> alive : noumber of children alive
> b : 1(boy), 2(girl), .(dead or not born)
> boyno : first boy or second boy, etc.
> cno : first child or second child, etc. (only alive children)
>
>
> 1. I want to first generate the following variables:
>
> local i 1
> while `i' <= 7 { \\There are a maximum of 7 children in any family
>
> local j 1
> while `j'<= `j' {
> gen p`i'`j'=0
> local j= `j' + 1
> }
> local i = `i' + 1
> }
>
>
> local k = `nboy'
> local i 1
> forvalues i=1(1)`k' {
> replace p`dfsize'`k' = (0.5)^`alive'
> }
>
> I can do this step.
>
> 2. Now I want to replace the value of p`dfsize'`k' with 0 whenever the
> kth (k runs from 1 to `nboy') boy is not the Nth child. For instance,
> for the family with id==1, I would want: p41=0, p42=0,
> p43=(0.5)^4. For
> the second family (id==2), I would want: p51=0, p52=(0.5)^3, p53=0,
> p54=0. (Note that I want the p* variables to have a single value for
> each family.)
>
> This is where I am stuck.
>
> 2. Later, I want to get back to the -wide- format because I
> want to use
> the p* variables for my ML estimation.
>
> Any suggestions will be appreciated.
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/