Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: How to genrate a variable containing some values of other variable


From   daniel klein <klein.daniel.81@googlemail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How to genrate a variable containing some values of other variable
Date   Thu, 5 May 2011 15:39:21 +0200

Problem seems solved but I just wanted to point out that there is no
need to loop over observations here.

/*---Example---*/

set obs 301
g old = _n

sort old // I know it is already sorted
g int new = 1 in 1
replace new = new[_n -1] + 5 in 2/`= 305/5'

/*---End---*/

Best
Daniel
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index