Statalist


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

Re: st: forvalues and _N


From   Tim <lists@timbp.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: forvalues and _N
Date   Fri, 10 Oct 2008 18:40:10 +1100

local N = _N
forvalues i = 1/`N' {
...
}

I don't think you can use a variable in a numlist (which value of the variable would you use?).

Tim

Bastian Steingros wrote:
Hi Stata users,

I have been searching for a special command in regard to *forvalues*, but without success.

I need something like:

gen N=_N

forvalues i = 1/N {
...
}

In my case, N is the maximum number of observations in my sample. I do not want to write 22345 or something instead of N because the number of observations might vary depending on how many observations I have dropped before.
But it is not possible to use N in a loop command at this place.


Are you aware of any stata updates being a solution to that problem?

Do you know a way to program it any better?

cheers

Bastian M Steingros



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