Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: cumulate values of X whithin group


From   Robert A Yaffee <bob.yaffee@nyu.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: cumulate values of X whithin group
Date   Sun, 06 May 2007 22:10:35 -0400

Dear Sara,
  Perhaps you want a program such as the following:

gen member=substr(var1,1,6)
gen oldate = substr(var1,10,14)
gen x = substr(var1,29,4)
drop if _n ==1
destring member, replace
destring x, replace
drop if _n == 5
drop var1
gen date=date(oldate,"md20y")
format date %td
replace newx = sum(x)- x

Regards,
  Robert Yaffee






Robert A. Yaffee, Ph.D.
Research Professor
Shirley M. Ehrenkranz
School of Social Work
New York University

home address:
Apt 19-W
2100 Linwood Ave.
Fort Lee, NJ
07024-3171
Phone: 201-242-3824
Fax: 201-242-3825
yaffee@nyu.edu

----- Original Message -----
From: sara borelli <saraborelli77@yahoo.it>
Date: Saturday, May 5, 2007 2:45 pm
Subject: st: cumulate values of X whithin group
To: statalist@hsphsun2.harvard.edu


> Dear Statalist members,
> 
> I have the following question:
> 
> 
> Member       Date              X
> 133          04-05-2000        1
> 133          04-07-2000        4
> 133          05-06-2000        2
> 133          07-10-2000        3
> 
> 145          06-05-2000        5
> 145          06-15-2000       5
> 145          08-05-2000       0
> 145          10-20-2000       2
> 145         11-05-2000       4
> 145          12-03-2000      6
> 
> Within each member, I need to create a variable that
> cumulates the values of X up to the date of the
> current observation excluding the value of X of the
> current observation, that is I need to create Xnew
> such that:
> 
> Member   Date                   X    Xnew
> 133          04-05-2000        1     0
> 133          04-07-2000        4     1
> 133          05-06-2000        2      5
> 133          07-10-2000        3      7
> 
> 145          06-05-2000        5      0
> 145          06-15-2000       5       5  
> 145          08-05-2000       0       10
> 145          10-20-2000       2       10
> 145         11-05-2000       4        12
> 145          12-03-2000      6        16
> 
> any help would be really appreciated
> Sarastatalist@hsphsun2.harvard.edu
> 
> 
> 
>       ___________________________________ 
> L'email della prossima generazione? Puoi averla con la nuova Yahoo! 
> Mail: http://it.docs.yahoo.com/nowyoucan.html
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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