Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: take the age of one observation and attach it to its matching observation by id with events accruing over time intervals


From   "Eric Fail" <[email protected]>
To   [email protected]
Subject   Re: st: take the age of one observation and attach it to its matching observation by id with events accruing over time intervals
Date   Fri, 16 Oct 2009 22:23:00 +0200

Thanks a lot. I got three quick answers to my problem.

Both the tip below and the tip from Jeph Herrin worked when I changed the  "merge 1:1 id date
using `foo' " to "merge id date using `foo'" in  Scott Merryman's code and the "merge 1:1 year
id using temp" to "merge year id using temp" in Jeph Herrin's code. Their examples apparently
work in Stata 11, but since I?m only using 10.1. I had to make that change.

I couldn't get Austin Nichols' code to work directly and since I already got the two other
working pieces of code I didn't really tried to get the last piece of code to work. I have
read the http://www.stata.com/support/faqs/data/members.html but I can't seem to translate the
examples in there to my case.

Anyhow, thanks to all for the help!

Regards

Eric


> clear
> input str17   date            year     id   spouse_id age goal_spouse_age
>             "01/01/2000"     2000      1         4    40    19
>             "01/01/2001"     2001      1         4    41    20
>             "01/01/2002"     2002      1         5    42    40
>             "01/01/2000"     2000      2         6    24    24
>             "01/01/2001"     2001      2         7    25    40
>             "01/01/2000"     2000      3         8    20    16
>             "01/01/2001"     2001      3         8    21    17
>             "01/01/2002"     2002      3        11    22    44
>             "01/01/2003"     2003      3         4    23    22
>             "01/01/2000"     2000      4         1    19    40
>             "01/01/2001"     2001      4         1    20    41
>             "01/01/2002"     2002      5         1    40    42
>             "01/01/2000"     2000      6         2    24    24
>             "01/01/2001"     2001      7         2    40    25
>             "01/01/2000"     2000      8         3    16    20
>             "01/01/2001"     2001      8         3    17    21
>             "01/01/2002"     2002     11         3    44    22
>             "01/01/2003"     2003      4         3    22    23
> end
>
> sort id date
> tempfile foo
> preserve
> keep date spouse age
> rename spouse id
> rename age age2
> sort id date
> save `foo'
> restore
> merge 1:1 id date using `foo'
> compare age2 goal
> l
>
> Scott
>
>
> On Fri, Oct 16, 2009 at 2:25 PM, Eric Fail <[email protected]> wrote:
>> Dear all
>>
>> After hours of reading and fiddling around I allow myself to write on the Statalist in the
>> hope that someone out there will take the time to help me.
>>
>> What I want to do seem quite simple but I just can?t figure it out.
>>
>> I simply want to take the age of one spouse and attach it to its matching spouse by id, so I
>> get a spouse_age at each observation.
>


*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index