I am Nithya. This is my first post, and i've tried to follow the advice on posting. But please excuse if I've missed something.
I have a string variable childgender with values=male,female. I am trying to create two separate variables countmale and countfemale with the number of male and female children in each household (hhid). I am The code i'm using is:
Code:
levelsof childgender, local(gender) foreach sex of local gender{ bysort hhid:egen count`sex'=count(childgender) if childgender=="`sex'" ta count`sex' egen n`sex'=max(count`sex'),by(hhid) replace n`sex' =0 ==mi(n`sex') }
Code:
egen n`sex'=max(count`sex'),by(hhid)
0 Response to using egen's max function with a local
Post a Comment