Statalist


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

RE: st: Creating a variable with gaps


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Creating a variable with gaps
Date   Thu, 19 Mar 2009 15:37:10 -0000

An orthogonal comment on a small matter of efficiency and style: 

It is never necessary to fire up a command (here -describe-) just to
find out the number of observations. Stata already knows what that is. 

forval m = 1(1000)`=_N' { 

forval m = 1(1000)`c(N)' {

are alternatives. 

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


Johannes Geyer

You could work with a loop and -in-:

************************************
gen x = .
qui des
forvalues m = 1(1000)`r(N)' {
        replace x = something in `m'
        }
************************************

Note that this assigns a value to observation 1, 1001, 2001, ... , last 
observation. 

*
*   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   |   What's new   |   Site index