[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: Re: Count occurrence and duration of states in panel data |

Date |
Mon, 1 Jun 2009 00:57:05 +0200 |

<>

I know where your code comes from.

********** clear input id begin end state 1 12 14 1 1 15 46 2 1 47 52 3 1 59 66 2 1 70 80 1 1 81 88 2 1 89 105 1 2 14 21 2 2 55 59 3 2 61 109 1 2 110 115 2 2 116 200 1 end list, noobs sepby(id) qui{ gen count=. forv i=1/`=_N'{ cou if inrange(begin[`i']-end, 1,30) & /// state==2 & /// id == id[`i'] replace count=r(N) in `i' } } list, noobs sepby(id) ********** HTH Martin _______________________

To: <statalist@hsphsun2.harvard.edu> Sent: Monday, June 01, 2009 12:04 AM Subject: Re: st: Re: Count occurrence and duration of states in panel data

Thanks for the up front comment but I defined count before the forvalcommand, otherwise the -forv- will not work.Do you have any suggestions regarding my question (which I summarize belowfor convenience)? Can I use inrange for my problem, i.e with begin and enddate? How to write it such that it works? Sorry, if this questions soundtoo easy for you but I try hard since days.clear input Id begin end state s2 res, auto 1 12 14 1 . 0 1 15 46 2 1 0 1 47 52 3 . 1 1 59 66 2 1 1 1 70 80 1 . 1 1 81 88 2 1 1 1 89 105 1 . 2 2 14 21 2 1 0 2 55 59 3 . 1 2 61 109 1 . 0 2 110 115 2 1 0 2 116 200 1 . 1 end gen count = . local N = _N qui forval i = 1/`N' { egen tag = tag(s2) /// if Id == Id[`i'] & /// inrange(begin, begin[`i'] - 30, end) count if tag == 1 replace count = r(N) in `i' drop tag } l, sepby(Id) I want to know how often a person has been in a certain state (e.g. state 2) during the past 30 days before the current state. Important is that the current state should not count. I have data in which the time intervals are not of equal length. And to keep things for the moment simple I defined a variable s2 which takes on the value 1 if the state of interest occurs. The variable res shows my desired results. The next step would be to calculate the duration the person has been in s2 during the past 30 days. If there is a related solution I would be extremely happy if you let me know this as well. -----Ursprüngliche Nachricht----- Von: "Martin Weiss" <martin.weiss1@gmx.de> Gesendet: 31.05.09 15:50:53 An: <statalist@hsphsun2.harvard.edu> Betreff: st: Re: Count occurrence and duration of states in panel data <> Two observations up front: You do not have to use -:mylabel, auto- here. I used it a while backto -input- a string that should have labels attached automatically, butyourvars are numeric. In your -forv- you replace the variable "count" which does not exist. You also want to make "Id" lowercase for your code to stand a chance... HTH Martin _______________________----- Original Message -----From: <go.diva@web.de>To: <statalist@hsphsun2.harvard.edu> Sent: Sunday, May 31, 2009 3:07 PM Subject: st: Count occurrence and duration of states in panel dataI want to know how often a person has been in a certain state (e.g. state 2) during the past 30 days before the current state. Important is that the current state should not count. I have data in which the time intervals are not of equal length. And to keep things for the moment simple I defined a variable s2 which takes on the value 1 if the state of interest occurs. The variable res shows my desired results. clear input id begin end state s2 res :mylabel , auto 1 12 14 1 . 0 1 15 46 2 1 0 1 47 52 3 . 1 1 59 66 2 1 1 1 70 80 1 . 1 1 81 88 2 1 1 1 89 105 1 . 2 2 14 21 2 1 0 2 55 59 3 . 1 2 61 109 1 . 0 2 110 115 2 1 0 2 116 200 1 . 1 end I followed some earlier questions at statalist and stata tips 39, 51 on inrange and events in intervals: gen count = . local N = _N qui forval i = 1/`N' { egen tag = tag(s2) /// if Id == Id[`i'] & /// inrange(begin, begin[`i'] - 30, end) count if tag == 1 replace count = r(N) in `i' drop tag } l, sepby(Id) I surmise that the inrange command is not appropriate. As s2 should also count if even the begin date has been more than 30 days away but theperson is in the state within the 30 day interval (with respect to theenddate),Can inrange be adjusted such that it takes the begin date and the enddateinto account? Do I have to think about an entirely different approach?The next step would be to calculate the duration the person has been ins2during the past 30 days. If there is a related solution I would be extremely happy if you let me know this as well. Any ideas will be appreciated! Elke ____________________________________________________________ Text: GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT! Jetzt freischalten unter http://movieflat.web.de * * 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/* * 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/ ____________________________________________________________ Text: GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT! Jetzt freischalten unter http://movieflat.web.de * * 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/

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

**References**:**Re: st: Re: Count occurrence and duration of states in panel data***From:*go.diva@web.de

- Prev by Date:
**Re: st: Re: Count occurrence and duration of states in panel data** - Next by Date:
**st: alternative specification for Oaxaca decomposition?** - Previous by thread:
**Re: st: Re: Count occurrence and duration of states in panel data** - Next by thread:
**st: alternative specification for Oaxaca decomposition?** - Index(es):

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