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: RE: Create a Running Count Variable?


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Create a Running Count Variable?
Date   Fri, 20 May 2011 19:57:05 +0100

bysort Fid (Chid) : gen NUML = sum(LOWB[_n - 1]) 

Nick 
n.j.cox@durham.ac.uk 

Don Ruby

Suppose I have the following data, where NUML is the variable I want to create.

    +---------------------------------------------------------+
     |  Fid   CHid  YOB  LOWB      NUML      |
     |----------------------------------------------------------|
 1. |    1      11    80         1              0         |
 2. |    1      12    82         0              1         |
 3. |    2      21    78         1              0         |
 4. |    2      22    85         1              1         |
 5. |    2      23    88         1              2         |
    +---------------------------------------------------------+

Where Fid is a family id, CHid is a child id, YOB is year of child's
birth, LOWB is an indicator for whether the child was born with low
birth weight, and NUML is the number of LOWB siblings born previously.

How can I create this running count variable, NUML?


*
*   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–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index