Bookmark and Share

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: on data transformation


From   "Lima, Julie" <[email protected]>
To   [email protected]
Subject   Re: st: on data transformation
Date   Wed, 20 Jul 2011 14:56:10 -0500

I'm not sure if I'm reading your data correctly, but there are a few
ways you could do it.  I would try the following:

sort by x and year, create a variable that indicated the maximum value
for event in a given year per x, and then keep only those observations
where this new variable==1.  So,...

sort x year
by x year: egen evtyr=max(event)
keep if evtyr==1

Assuming, event is 1 or missing (and there are no other values), The
first 2 lines should result in the following:

> x  week      var1  var2 year event  evtyr
>
> x1 2006w2 var1 var2 2006
> x1 2006w3 var1 var2 2006
> x1 2006w4 var1 var2 2006
> x1 2007w7 var1 var2 2007            1
> x1 2007w8 var1 var2 2007            1
> x1 2007w9 var1 var2 2007            1
> x1 2007w10 var1 var2 2007 1        1
>
> x2 2008w2 var1 var2 2008
> x2 2008w3 var1 var2 2008
> x2 2008w4 var1 var2 2008
> x2 2009w9 var1 var2 2009            1
> x2 2009w8 var1 var2 2009            1
> x2 2009w9 var1 var2 2009            1
> x2 2009w10 var1 var2 2009 1        1

then the last line would keep all obervations within the year of
interest (evtyr=1) for each x .

Goodluck, Julie


On Wed, Jul 20, 2011 at 2:41 PM,  <[email protected]> wrote:
> Dear all,
>
> I would like to ask for help with data transformation. I have data on objects
> x1, x2,x3  that are observed over time (weeks). I have variables var1 and var2
> for each objects and also variable indicating the year of observation. In
> addition, a variable "event" indicates the time period when an event has
> occurred.
>
>
> The columns of the panel data set look as follows:
>
> x  week      var1  var2 year event
>
> x1 2006w2 var1 var2 2006
> x1 2006w3 var1 var2 2006
> x1 2006w4 var1 var2 2006
> x1 2007w7 var1 var2 2007
> x1 2007w8 var1 var2 2007
> x1 2007w9 var1 var2 2007
> x1 2007w10 var1 var2 2007 1
>
> x2 2008w2 var1 var2 2008
> x2 2008w3 var1 var2 2008
> x2 2008w4 var1 var2 2008
> x2 2009w9 var1 var2 2009
> x2 2009w8 var1 var2 2009
> x2 2009w9 var1 var2 2009
> x2 2009w10 var1 var2 2009 1
>
> I have many variables x that differ in number of weeks and years. I need however
> to keep the year when the event has happened and dropped any previous years.
> Given my data set, is this possible to be done in Stata?
>
>
> Many thanks in advance.
>
> KR,
> Rado
>
>
> *
> *   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/
>



-- 
*************************************
Julie Lima, MPH, PhD
Senior Research Analyst
Brown University
Center for Gerontology and Health Care Research
Providence, RI

Mailing Address
1316 Old Oak Trail
Flower Mound, TX 75028
p: 972-355-7814

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index