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: How to change a household-level data set into a respondent-level data set?
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: How to change a household-level data set into a respondent-level data set?
Date
Sun, 17 Jun 2012 01:46:42 +0100
local N = _N
expand 2 if SpouseID
replace FamR = _n <= `N'
gen hold = SpouseID
replace SpouseID = PersonID if FamR == 0
replace PersonID = hold if FamR == 0
drop hold
On Sun, Jun 17, 2012 at 12:11 AM, xueliansharon <[email protected]> wrote:
>
> I want to change a household-level data set into a respondent-level data
> set, but I don't know how to program to realize it.
>
> The procedure is as follows:
>
> One section of my data set is household-level, i.e., there's only one record
> for each household, and the survey is answered by a family respondent for
> each household. The original data structure is like:
>
> FamR PersonID SpouseID household income own a house
> 1 1010 1020 100000 1
> 1 2020 2010 20000 0
> 1 3040 3041 50000 0
> 1 4020 0 70000 1
> 1 5030 0 40000 0
>
> Here, the first variable "FamR" is a dummy indicating whether the individual
> is a family respondent ("1" implies yes). "PersonID" provides the ID for the
> individual, and "SpouseID" provides the ID for the individual's spouse. When
> SpouseID=0, it means that the individual doesn't have a spouse. "Household
> income" and "Own a house" (dummy) are two variables for each household.
>
> Now I want to change it into a respondent-level structure, i.e. I want to
> generate a record for the family respondent's spouse for each household. The
> new data structure should be like:
>
> FamR person ID spouse ID household income own a house
> 1 1010 1020 100000 1
> *0 1020 1010 100000 1*
> 1 2020 2010 20000 0
> *0 2010 2020 20000 0*
> 1 3040 3041 50000 0
> *0 3041 3040 50000 0*
> 1 4020 4021 70000 1
> 1 5030 5033 40000 0
>
> Please note that, for those added non-family respondents, his/her "person
> ID" (e.g. 1020) is the "spouse ID" of the family respondent in the
> household, and his/her "spouse ID" (e.g. 1010) is the "person ID" of the
> family respondent in the household.
*
* 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/