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]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: how can I use noof obs in Syntax |

Date |
Wed, 24 Oct 2012 09:53:21 +0100 |

Let's take that more slowly. Rasool's intention is evidently that the number of observations in the current dataset gives the default. The immediate problem is that -syntax- won't evaluate expressions for you. Maarten's solution subverts that by getting the part of Stata that processes your input to substitute the current value of _N as an integer before -syntax- sees "_N". But that will wire into the definition of the program whatever that currently is: 0, 74, or whatever. If Rasool or any other user changes the size of the dataset while using the program, then there will be a problem. There are at least two easy work-arounds. One is to have an impossible default that no-one would specify noobs(integer -1) Then change -1 to whatever _N is if `noobs' == -1 local noobs = _N That is, if the default value is still in place after -syntax-, the option was never specified, so we use the value of _N. This should be done when it is needed, and as before the effect is to define -noobs- as a constant. If the dataset changes in size, -noobs- will not adjust automatically. Another is to use a -numlist- noobs(numlist int max=1 >0) Then if "`noobs'" == "" local noobs = _N That's a similar solution; some might regard it as more elegant or more transparent. Nick On Wed, Oct 24, 2012 at 8:34 AM, Maarten Buis <maartenlbuis@gmail.com> wrote: > On Wed, Oct 24, 2012 at 6:35 AM, rasool.bux wrote: >> How I can use as an option in Syntax noobs(integer _N) is giving a syntax error. >> >> syntax varlist(min=2) [if] [in] [, REPS(integer 50) noobs(integer _N) seed(integer 1) ] > > noobs(integer `=_N') > * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/

**References**:**st: how can I use noof obs in Syntax***From:*"rasool.bux" <rasool.bux@aku.edu>

**Re: st: how can I use noof obs in Syntax***From:*Maarten Buis <maartenlbuis@gmail.com>

- Prev by Date:
**Re: st: how can I use noof obs in Syntax** - Next by Date:
**RE: st: how to store matrix in a data file** - Previous by thread:
**Re: st: how can I use noof obs in Syntax** - Next by thread:
**Re: st: how can I use noof obs in Syntax** - Index(es):