Hi,
I want to create a variable that gives me the amount of children aged 17 and younger (children17) for each household.
For that I have these vars:
hhid -> household id
pid_1 - pid_8 -> id of the individual in the household between 1 and 8 (so a person can have no. 1, 2,3...or 8 referring to a certain household id)
age_1 - age_8 -> age of each individual (no.1 - no.8) in a household
relrefp -> the relationship to the reference person of the hh: each of the children need relrefp==3 (daughter/son)
I tried to create such a variable with a loop several ways but somehow I do not find the correct solution.
forv i = 1(1)8 {
2. gen children17=`i' if age_`i'<=17 & relrefp_`i'==3
3. }
This is probably still not that close to the solution, as stata tells me that "variable children17 already defined", though it´s not in the datasat before starting the loop.
Perhaps someone with much more experience in stata loops can give me the right hints?
Related Posts with Loop over households and individuals
generating counterfactual when I have adjusted for a control in Interrupted time seriesDear colleagues i have a model: arima lograte time vacperiod strike malnutration, arima(1,0,0) . Whe…
Creation of cumulative lead variableHi all, my Data looks like the following: Code: * Example generated by -dataex-. For more info, t…
A question of Cox PH modelHello, everyone! I have a question about the Cox PH model in Stata, I know how to use the command st…
List of observations in regressionHello, I am running a regression in STATA (xtgee). xtgee Profit number_employees company_size , li…
Panel data: Multiple IDs, partly duplicatedI have received panel data that need lots of cleaning. The most substantial challenge is finding a u…
Subscribe to:
Post Comments (Atom)
0 Response to Loop over households and individuals
Post a Comment