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: how to reshape data so that can perform calculations


From   Neil Shephard <[email protected]>
To   [email protected]
Subject   Re: st: how to reshape data so that can perform calculations
Date   Tue, 22 Mar 2011 15:57:47 +0000

On Tue, Mar 22, 2011 at 3:10 PM, Kathleen Oberst
<[email protected]> wrote:
> I have a dataset with person ID, discharge date, and another calculated
> field in a long format as follows:
>
> Id      discharge date  daysmissed      y
> x       1/1/2010                14              1
> x       2/1/2010                9               2
> y       1/5/2010                0               1
> z       2/8/10          25              1
> z       4/10/10         19              2
> z       9/30/10         8               3
>
>
> I'm trying to keep just those records of people who had >1 discharge and
> then I want to calculate the elapsed time between dicharges. I generated
> a marker 'y' to act as a counter for #admissions but can't really drop
> anyone where y equals 1 because I will need that first d/c date for the
> subsequent calculation. I've not had luck with reshape.

You've not shown us how you created y, but one way to get it such that
its the total number of observations for a given Id is....

bysort Id (dischargedate) : gen y = _N

...because _N is the total number of observations _within_ the defined
group. You can then drop those individuals who only have one recorded
discharge date with...

drop if(y == 1)

Useful reading would be...

Cox NJ (2002) Speaking Stata: How to move step by: step. The Stata
Journal 1:86-102

Neil


-- 
“Truth in science can be defined as the working hypothesis best suited
to open the way to the next better one.” - Konrad Lorenz

Email - [email protected]
Website - http://kimura.no-ip.org/
Photos - http://www.flickr.com/photos/slackline/

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