[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 |
st: AW: count with a loop |

Date |
Wed, 16 Dec 2009 09:34:31 +0100 |

<> Try this very carefully to see whether it does what you want: ************* clear* inp byte personid str20(dateposted datefunded) 1 "2009-04-04 3:20:08" "2009-04-04 10:00:14" 2 "2009-04-04 5:20:08" "2009-04-04 11:02:14" 3 "2009-05-04 2:20:08" "2009-05-04 11:02:14" 4 "2009-05-04 2:20:02" "2009-05-04 11:02:17" 5 "2009-05-04 2:12:02" "2009-05-04 11:04:17" end compress gen double timeposted= clock(dateposted, "YMDhms") gen double timefunded= clock(datefunded, "YMDhms") format timeposted timefunded /* */ %tcMon_DD,_CCYY_HH:MM:SS drop date* //maximum possible sort timeposted gen count=_n-1 //check second condition //conditional on first being met forv i =1/`=_N'{ qui cou if timefunded<timeposted[`i'] in 1/`i' replace count=count-`r(N)' in `i' } li, noo ************* HTH Martin -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von LY Pierrem Gesendet: Mittwoch, 16. Dezember 2009 09:16 An: statalist@hsphsun2.harvard.edu Betreff: st: count with a loop Dear Stata list, I have a data set that looks like this personid dateposted datefunded 1 2009-04-04 3:20:08 2009-04-04 10:00:14 2 I am trying to create a new variable, which for each person n, would count the number of people such that 1. they were posted before person n AND 2. were funded after person n was posted. In other words, this would count the number of people active (i.e. posted but not yet funded) on the database at the time each person n is posted. It seems that a simple egen and conditional count are not good enough for the purpose. Is a loop necessary for this? I have an idea that a loop is needed here (maybe using forval?) but any help would be greatly appreciated! Thanks for any suggestions! Pierre * * 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/

**Follow-Ups**:**Re : st: AW: count with a loop***From:*LY Pierrem <lypierrem@yahoo.fr>

**st: RE: AW: count with a loop***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: count with a loop***From:*LY Pierrem <lypierrem@yahoo.fr>

- Prev by Date:
**Re: st: estimating an asymmetrical relationship** - Next by Date:
**RE: st: Choice of analysis time in survival analysis where the hazard is associated with age** - Previous by thread:
**st: count with a loop** - Next by thread:
**st: RE: AW: count with a loop** - Index(es):

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