[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
STATA Dndee <statadndee@yahoo.co.uk> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
RE: st: add up the total stay |

Date |
Fri, 12 Oct 2007 19:31:40 +0100 (BST) |

I need expression and commands to tell STATA; If “id” is the same as previous observation and if “in” for this observation equals to “out” in previous one, then add “ stay” to previous one to calculate StayEachVisit. And consider that number of observations for total stay in each visit is not defined (in the example it is 1-2 but it can be one 1-7 or more). Many thanks --- STATA Dndee <statadndee@yahoo.co.uk> wrote: > Thanks for replies. > I am new to STATA and this discussion board and > apparently I couldn’t describe my question. It is > not > about destring the variables to date format. I can > manage that with this command for example for > DateA:: > gen NewVar = date( DateA, "dm20y") > format NewVar %td > My problem is to calculate 2 variables : > datecamedatewent and totalstayeachvisit in STATA > for > the example it’s been done manually. > So there is 1 questions > 1) In STATA how can I manage to get total staye > each > visit regarding that it depends on id and any > continues staying refer to columns In and Out > variables. What is the command to manage to get 2 > outputs for SD101 and not 3? > > I don’t know where that 0.1 came from, the data are > here again. > Your help is very much appreciated. > > +-------------------------------------------------+ > id In Out Stay StayEa~t > ------------------------------------------------- > 1. SD101 05nov2005 05nov2005 .5 _ > 2. SD101 05nov2005 11nov2005 6 6.5 > 3. SD101 28apr2005 28apr2005 .5 0.5 > 4. SD105 03jul2006 03jul2006 .5 0.5 > 5. SD105 29mar2006 29mar2006 .5 0.5 > ------------------------------------------------- > 6. SD105 13jan2006 14jan2006 1 - > 7. SD105 10jan2006 13jan2006 3 4 > 8. SD105 24may2004 25may2004 1 1 > 9. SD217 22sep2005 22sep2005 .5 0.5 > +-------------------------------------------------+ > Many thanks > > > > --- Nick Cox <n.j.cox@durham.ac.uk> wrote: > > > I think Arun later answered the question about > > two-digit years in dates himself (or herself). > > > > Just one tip: If I see sample data like > > > > SD101 05-Nov-05 05-Nov-05 > > SD101 05-Nov-05 11-Nov-05 > > SD101 28-Apr-05 28-Apr-05 > > SD105 03-Jul-06 03-Jul-06 > > SD105 29-Mar-06 29-Mar-06 > > SD105 13-Jan-06 14-Jan-06 > > SD105 10-Jan-06 13-Jan-06 > > SD105 24-May-04 25-May-04 > > SD217 22-Sep-05 22-Sep-05 > > > > in a Statalist posting, I wouldn't go the -infix- > > route. I copy and paste that into an empty > > Stata data editor window. Often the results > > end up as a single string variable, but that > > is often fixable with a single > > > > split var1, destring > > > > followed by a little cleaning up. In this case > > the dates remain together within single variables. > > > > Nick > > n.j.cox@durham.ac.uk > > > > Arun Rajamohan > > > > > I am not sure what you mean by database. > Hopefully > > it is convertible > > > to excel or raw or csv file. I draged the sample > > data from > > > your email > > > and saved it as a raw file. Then I loaded it > into > > stata using infix. T > > > > > > Your sample dataset is, > > > > > > SD101 05-Nov-05 05-Nov-05 > > > SD101 05-Nov-05 11-Nov-05 > > > SD101 28-Apr-05 28-Apr-05 > > > SD105 03-Jul-06 03-Jul-06 > > > SD105 29-Mar-06 29-Mar-06 > > > SD105 13-Jan-06 14-Jan-06 > > > SD105 10-Jan-06 13-Jan-06 > > > SD105 24-May-04 25-May-04 > > > SD217 22-Sep-05 22-Sep-05 > > > > > > I sucked it up into stata using infix ... > > > > > > infix str id 1-5 str d1 7-8 str m1 10-12 y1 > 14-15 > > str d2 > > > 17-18 str m2 > > > 20-22 y2 24-25 using ~/desktop/stay.raw, clear > > > > > > Now you will have your data in stata looking > like > > this... > > > > > > id d1 m1 y1 d2 m2 y2 > > > SD101 05 Nov 05 05 Nov 05 > > > ... > > > > > > Then you may have to add 2000 to the year > values. > > > > > > [I would appreciate if someone can update me on > an > > alternate method. > > > Some of my own datasets have years in the format > > 96, 97, 01, 04 etc. > > > instead of 1996, 1997, 2001, 2004... Stata date > > system does not like > > > years in 2 digit format. Am I right? I've always > > had to use a > > > do file > > > to sort through the years and convert them.] > > > > * > > * For searches and help try: > > * > > http://www.stata.com/support/faqs/res/findit.html > > * http://www.stata.com/support/statalist/faq > > * http://www.ats.ucla.edu/stat/stata/ > > > > > > > ___________________________________________________________ > Yahoo! Answers - Got a question? Someone out there > knows the answer. Try it > now. > http://uk.answers.yahoo.com/ > * > * For searches and help try: > * > http://www.stata.com/support/faqs/res/findit.html > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > ___________________________________________________________ Want ideas for reducing your carbon footprint? Visit Yahoo! For Good http://uk.promotions.yahoo.com/forgood/environment.html * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**RE: st: add up the total stay***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**RE: st: add up the total stay***From:*STATA Dndee <statadndee@yahoo.co.uk>

- Prev by Date:
**RE: st: add up the total stay** - Next by Date:
**st: re: dummy for multiple intervals** - Previous by thread:
**RE: st: add up the total stay** - Next by thread:
**RE: st: add up the total stay** - Index(es):

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