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]

st: replacing previous observations according to current observation, foreach? replace?


From   Charlotte Picard <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: replacing previous observations according to current observation, foreach? replace?
Date   Thu, 2 Dec 2010 14:14:20 -0500

Hello Stata users,
I am a new stata user and I am trying to work backwards in my data.

Region Week Cases
1             1       5
2             1       4
3             1       0
4             1       2
1             2       3
2             2       2
3             2       1
4             2       0
1             3       2
2             3      -3
3             3       0
4             3       4

I am trying to create code that will find negative values for Cases and subtract them to the cases from the previous week, if that weeks cases then become negative it will subtract them from the week before that and so on until the case count isn't negative anymore and fill in these new values of case in a new variable.  I want to do this within each region seperately but I'm having trouble determining if I need to make some sort of foreach loop, which I've never tried before of if there is a simpler way.

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