Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Stas Kolenikov <skolenik@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: _byn1() and _byn2() variables in numlist |
Date | Mon, 27 Sep 2010 17:20:54 -0500 |
is this what you are trying to do? program testing, byable(recall) marksample touse local last = _byn2() local first = _byn1() forvalues i=`last'(-1)`first' { di `i' } end _byn1() and _byn2() return you numbers, while -forvalues- needs a string representation of a number. May be you can get along with -forvalues `=_byn2()'(-1)`= _byn1()' { }- although that is somewhat convoluted and difficult to read. On Mon, Sep 27, 2010 at 4:39 PM, Poliquin, Christopher <cpoliquin@hbs.edu> wrote: > Hello, > > I am attempting to use the _by variables in a byable program, but am running into problems with syntax problems and invalid numlists that I cannot figure out how to resolve: > > I do... > > . program testing, byable(recall) > 1. marksample touse > 2. di _byn2() > 3. di _byn1() > 4. forvalues x = _byn2()(-1)_byn1() { > 5. di `x' > 6. } > 7. end > . bys foo : testing > > > And get ... > ---------------------- > -> foo = 1 > 2 > 1 > invalid syntax > r(198); > > And when using a numlist, i.e. foreach x of numlist _byn2()(-1)_byn1(), I get an invalid numlist error. > > How do I cycle through each observation number in a group within a byable program? -- Stas Kolenikov, also found at http://stas.kolenikov.name Small print: I use this email account for mailing lists only. * * 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/