Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: forvalues and _N


From   "Nichols, Austin" <ANichols@ui.urban.org>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: forvalues and _N
Date   Thu, 2 Sep 2004 17:05:37 -0400

That's a very handy tool, indeed.  Cf.

#delimit;
forval e = 1/5 {; di `e'; };
forval e = 1/2+3 {; di `e'; };
forval e = 1/`=2+3' {; di `e'; };

where the second example bombs for the same (?) reason 
as forval e = 1/_N  but the third runs fine.

-----Original Message-----
From: Fred Wolfe [mailto:fwolfe@arthritis-research.org]
Sent: Thursday, September 02, 2004 5:00 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: forvalues and _N


This will work:

forval e = 1/`=_N'

Fred Wolfe

At 01:45 PM 9/2/2004 -0700, you wrote:
>I have a problem using a forval loop to assign values to a numeric variable
>(for brevity, assume that -encode- doesn't work here).  I want to loop
>through the entire dataset, addressing each value in turn, so
>
>.forval e = 1/_N
>
>would appear to be the appropriate form.  I get an "invalid syntax" error
>when I do so.
>
>.di _N
>
>gives me the expected result for this dataset, 2339.
>
>.forval e = 1/2339
>
>works as expected.
>How am I screwing this up?

---------------------------------
Fred Wolfe (fwolfe@arthritis-research.org)
National Data Bank for Rheumatic Diseases
Arthritis Research Center Foundation
Wichita, KS USA
*
*   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