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 create a dummy with information across rows
From
ana mylena aguilar <[email protected]>
To
statalist <[email protected]>
Subject
Re: st: how to create a dummy with information across rows
Date
Fri, 6 Dec 2013 13:17:04 -0500
Thanks Both. These suggestions put me on good track.
Ana
On Thu, Dec 5, 2013 at 8:53 PM, Matt Vivier <[email protected]> wrote:
> Hi Ana,
>
> I imagine someone on this list has a more graceful solution, but this
> should work:
> --Sample Data-- (saved as data.dta)
> household roster_line age relationship mother_line
> 1 1 35 head
> 1 2 15 daughter
> 1 3 10 daughter 1
> 1 4 1 grandson 2
> 2 1 45 head
> 2 2 25 daughter
> 2 3 25 son
> 2 4 25 daughter
> 2 5 17 son
> 3 1 40 head
> 3 2 19 daughter
> 3 3 18 daughter
> 3 4 2 grandson 2
> 3 5 3 granddaughter 3
>
> use data, clear
> qui sum roster_line
> local max = r(max)
> keep household roster_line mother_line
> reshape wide mother_line, i(household) j(roster_line)
> sort household
> save wide, replace
> use data
> sort household
> merge m:1 household using wide
> gen teen_mom = 0
> forv m = 1/`max'{
> replace teen_mom =
> cond(inrange(age,13,19),max(teen_mom,cond(roster_line==mother_line`m',1,0)),0)
> }
>
> Two things to look out for:
> 1. This uses a very strict definition of "teen mom" that you may want to change
> 2. If you have very large households this could get very wide, but
> that seems unlikely
>
> Best of Luck,
>
> Matt Vivier
> Data Analyst
> (203) 541-4665
> Remedy Partners, Inc
>
>
> On Thu, Dec 5, 2013 at 6:11 PM, ana mylena aguilar <[email protected]> wrote:
>> Hello
>> I have a datatset with information by households ( rows) and
>> individual household members in the columns.Household size can go all
>> the way until 25. Therefore, the format for x number of variables is
>> for example age1..age25.I reshaped the dataset to have household
>> members within each household in each row as below. However, I need to
>> contruct a variable that require using infomation across rows.
>> hh roster line age rel with hh head child's mother line
>> (only <14 years old)
>> 1 1 35 household head
>> missing
>> 1 2 15 daughter missing
>> 1 3 10 daughter 1
>> 1 4 1 grandson 2
>> I need to create a dummy variable to identify a teen mother in the
>> household. In this case, there is one (line 2). The household is
>> formed by a mother, two daughters ( age 15 and 10) and a grandson. The
>> older daughter has a 1 year old child. Every child under 14 has
>> information on who is his/her biological mother ( roster line of the
>> mother). But I would like to link the information of the chidl with
>> the young mother. Do I need to re-reshape or a loop would work?
>>
>> Any help would be great, thanks
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/faqs/resources/statalist-faq/
>> * http://www.ats.ucla.edu/stat/stata/
>
> --
> The information contained in this transmission and any attachments may be
> confidential, proprietary or privileged, and may be subject to protection
> under applicable law. This transmission is intended for the sole use of the
> individual or entity to whom it is addressed. If you think you have
> received this transmission in error, please alert
> [email protected] and then delete this e-mail immediately.
> Thank you.
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/