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

Re: st: help with understanding syntax 'gen last=_n==_N'


From   "b. water" <[email protected]>
To   [email protected]
Subject   Re: st: help with understanding syntax 'gen last=_n==_N'
Date   Mon, 28 Nov 2005 09:13:19 +0000

thank you to both nick (cox) and sergio for the explanations. it was clearer with worked example.

regards,
bw



From: Sergio Correia <[email protected]>
Reply-To: [email protected]
To: [email protected]
Subject: Re: st: help with understanding syntax 'gen last=_n==_N'
Date: Sun, 27 Nov 2005 22:15:25 -0500

the -by- prefix repeats the command for each possible value of "study".

So, using _N returns the total number of obs. for each value of study.
_n returns the observation index (1,2,3,4..) within each value of study

Finally, _n=_N is true when the index is at its last position.

Sergio


On 11/27/05, b. water <[email protected]> wrote:
> dear listers,
>
> i am trying to understand one of the do-files application for stata. one of
> the lines read:
>
> qui by study: gen last=_n==_N
>
> my understanding so far: this is quietly, sort according to study, and as a
> result, to generate a variable last fulfilling this condition _n==-N.
> although i have the output, i would like to know what in general does gen
> last=_n==_N do?
>
> thank you,
> bw
>
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today - it's FREE!
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>
> *
> * 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/
_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to get there! http://lifeevents.msn.com/category.aspx?cid=Retirement

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index