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   Scott Merryman <[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 14:35:55 -0500

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