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: replacing previous observations according to current observation, foreach? replace?


From   Sergiy Radyakin <[email protected]>
To   [email protected]
Subject   Re: st: replacing previous observations according to current observation, foreach? replace?
Date   Fri, 3 Dec 2010 15:54:35 -0500

On Thu, Dec 2, 2010 at 2:14 PM, Charlotte Picard
<[email protected]> wrote:
> 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.


Dear Charlotte,

could you please clarify, whether the number of cases is
"number of cases in that week" or
"cumulative number of cases in all weeks precedeing
(and including) the current week"?

if you have weekly data then by definition what you are
looking for is the sum of all the cases (positive and negative).
E.g. if cases are patients, and positive are new patients, and
negative are patients that didn't survive, then you can find
the current number of patients in the hospital simply by
totalling the number of arriving and departing patients up
to that week.

It would be strange if the positives were cumulative stocks and
negatives were flows.

Best, Sergiy Radyakin

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index