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: Tracking & documenting Change
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Tracking & documenting Change
Date
Thu, 5 Apr 2012 19:20:31 +0100
There seems here an indication that -Ins- changes Year to Year, but in
that case why the duplicates? Note that the duplicates get in the way
of counting transitions.
But I have to take your example literally because you really don't
explain the precise rules.
Also, I assume -Ins- is string because you don't specify and it makes
the code easier. But if not, then use -decode- first and use the
result of that, not the numeric variable with labels.
gen Status = ""
sort ID Year
by ID: replace Status = "Stayed" if Year > Year[_n-1] & Ins == Ins[_n-1]
by ID: replace Status = "Changed" if Year > Year[_n-1] & Ins != Ins[_n-1]
by ID: replace Status = Status + " " + Ins + " " + Ins[_n-1] if
!missing(Status)
by ID: replace Status = Status[_n-1] if missing(Status)
Code not tested.
Nick
On Thu, Apr 5, 2012 at 7:05 PM, Rituparna Basu <[email protected]> wrote:
> I would like to track the change of insurance status of a person from year to year. After tracking, I would like to document them as %'stayed-same' , %'changed from A-B', etc.
> Here is the sample data:
> ID Year Insurance Status
> 1 04 A
> 1 04 A
> 1 04 A
> 1 04 A
> 1 05 B Changed A-B
> 1 05 B Changed A-B
> 1 05 B Changed A-B
> 1 06 B Stayed B
> 1 06 B Stayed B
> 1 06 B Stayed B
> 2 04 A
> 2 04 A
> 2 04 A
> 2 05 A Stayed A
> 2 05 A Stayed A
> 2 05 A Stayed A
> 2 05 A Stayed A
>
>
*
* 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/