I want to generate a binary variable name “eldest” as follows:
if a person is the most aged person in a household, then eldest =1,
if a person is NOT the most aged person in a household, then eldest =0
The command I used is as follows:
gen eldest=0
bysort hhid: replace eldest=1 if max(age)
by its says "Invalid syntax"
What is the problem?
What is the correct way to do it?
Thank You
Related Posts with max and if together
constrains in latent profile analysisDear scholars, I am struggling with the meaning of constrains in LPA. Stata's default constrain val…
generate a new variable when values switch in panelI have panel data that look like these first three columns below (state, year, length). I would like…
Create mother in law variables for female spouse in each householdHello Statalisters, I would like to generate for each spouse (female) in each household id (Fhhid),…
usage of `' in stata commandsHi, I am trying to understand the use of command `' in stata. For instance, if the command is "if `3…
Deducting values in panel data across observationsDear Statalist, I've tried finding an answer for this question for a while. I'm using the latest S…
Subscribe to:
Post Comments (Atom)
0 Response to max and if together
Post a Comment