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

RE: st: how to create case id number

From   "Eric G. Wruck" <>
Subject   RE: st: how to create case id number
Date   Fri, 29 Apr 2005 12:13:32 -0400

Hi Nick:

Could you please explain your second sentence below about _n being defined as 1?  In my new Stata 9 User's Guide (which arrived yesterday!) on page 148, I read

"_n contains the number of the current observation."

Adding to my earlier attempted explanation, I'll point out that Stata refers to variables such as _n as system or underscore variables.


>It is more the other way round. _n remains defined
>as 1 to whatever is _N regardless of the sort order
>of the data. Which observation is which is what varies.
>The consequences are much the same, naturally.
>Adding or deleting observations will change the range
>of _n, certainly.
>Eric G. Wruck
>> Stata does very little automatically.  One thing that it does
>> do automatically is create a variable _n that contains the
>> observation number or record number.  However, as soon as you
>> sort or do something with the data set, these _ns will
>> change.  So, to create the variable you seem to want, you'll
>> want to use the generate command (usually abbreviated gen):
> > gen case_id = _n



       Eric G. Wruck
       2535 Sherwood Road
       Columbus, OH  43209

       ph:      614.231.5034
       cell:    614.327.4182
       fax:     614.231.5039
       eFax:    614.573.6639

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index