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
Issues with inaccurate generate of a new variableHi there, I have recently used a very simple comand to generate a new variable. gen MFN_zero = Imp…
Difference-in-difference using tobit regression with mediation (controlling for fixed effects)Dear Statalist-users, I want to conduct a mediation analysis in a difference-in-difference setting.…
How to export the freqs of multiple variables from stata to excelHello , I have been using tabout to output summaries for 2 X 2 tables quite well. Now a new need ha…
putting multiple graphs for quantitative vs categorical variables in one graphHi, I have 7 variables, which are actually for one survey question that asks respondents to rank th…
invalid syntax when referencing to variable labels in loopsI'm trying to refer to the labels of variables (to include these in graph titles) when looping on a …
Subscribe to:
Post Comments (Atom)
0 Response to max and if together
Post a Comment