Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Generating dummy variable with information of household survey from different observations
From
Eric Booth <[email protected]>
To
[email protected]
Subject
Re: st: Generating dummy variable with information of household survey from different observations
Date
Sun, 6 May 2012 23:44:31 -0500
<>
***************!
clear
inp household_id individual_id father_row
1011 1 .
1011 2 .
1011 3 1
1011 4 1
1012 1 2
1012 2 .
1013 1 .
1013 2 .
1013 3 2
1013 4 1
1013 5 1
end
levelsof individual_id, loc(a)
reshape wide father_row, i(household_id) j(individual_id)
ds father_row*
loc checklist `r(varlist)'
loc checklist:subinstr loc checklist " " ", " , all
foreach n in `a' {
g father`n' = cond(inlist(`n', `checklist'), 1, 0, .)
}
reshape long father_row father, i(household_id) j(individual_id)
***************!
- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
+979.845.6754
On May 6, 2012, at 10:34 PM, Sumiko Hayasaka wrote:
> I am trying to generate a dummy variable, with information from a
> household survey, which can tell if a member of the household is a
> father or not. I have a household id, an individual id (per
> household), and a variable that tells me which individual id is marked
> as being a father (members of the family are asked if their father
> lives in the household and to give their father's individual id).
> Therefore, I need to assign a 1 at the row in which someone at the
> household said that was a father. To illustrate this, the data is
> something like this (I am trying to get the "father" variable):
>
> household_id individual_id father_row father
> ------------------------------------------------------------------------
> 1011 1 . 1
> 1011 2 . 0
> 1011 3 1 0
> 1011 4 1 0
>
> 1012 1 2 0
> 1012 2 . 1
>
> 1013 1 . 1
> 1013 2 . 1
> 1013 3 2 0
> 1013 4 1 0
> 1013 5 1 0
>
>
> So, for example, members number 3 and 4 of household number 1011
> stated that their father is individual number 1 in that household.
> This means that I have to put the 1 of "father" (meaning the household
> member is a father) at the row where father_row indicates (no matter
> how many times this is done).
>
> Is there any way in which I can do this? I really appreciate your
> help! Thank you!
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/