[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Joseph Coveney" <jcoveney@bigplanet.com> |

To |
"Statalist" <statalist@hsphsun2.harvard.edu> |

Subject |
Re: st: Re: Bug in -use- or -if- ? |

Date |
Sat, 7 Feb 2009 00:34:13 +0900 |

Sergiy, Stata must have separate observation number variables just as you describe. I think that _n is your MC. And that it doesn't change its role, not even in -use filename if _n >= 37-. Rather than trying to get _n to do what it apparently is not meant to, maybe it would be better to ask if/how you can get access to that file observation counter (your FC) that Stata must also have in order to -use filename in 37/l-. Joseph Coveney -------------------------------------------------------------------------------- Sergiy Radyakin wrote: I agree that this might be a plausible explanation of what's going on, but this is hardly what one would expect. E.g. when I type a variable name in {use filename.dta if age>18}, I mean the variable age in the dataset filename.dta, not in the current dataset in memory. Following the same logic, _n must also refer to the observation number in the file. Otherwise, what would be a valid example of using _n in an if-condition after -use-? (if I understand you correctly it will always evaluate either to zero or one for the whole statement -use-, not for each observation). The definition of _n that you quote never refers to the location of observations. "Number of current observation" where? In memory or in the file? For all other commands it is perfectly clear - in the memory. But for -use-, it just doesn't make sense to refer to memory since it just might be empty. Say, I am reading a file with use filename.dta if (age>18) & (int(_n/2)==_n/2) taking all even observations of persons older than 18. Then when Stata reads data it maintains two counters, one call it FC is the record number in the file, and another MC in the memory (and FC>=MC always). Evaluating _n to MC makes little sense since I may not a priori know how many results will the if-condition fetch. But evaluating _n to FC makes perfect sense because it defines which part of the file is eligible for load. * * 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/

**References**:**st: Bug in -use- or -if- ?***From:*Sergiy Radyakin <serjradyakin@gmail.com>

**st: Re: Bug in -use- or -if- ?***From:*"Joseph Coveney" <jcoveney@bigplanet.com>

**Re: st: Re: Bug in -use- or -if- ?***From:*Sergiy Radyakin <serjradyakin@gmail.com>

- Prev by Date:
**st: Scatter plot with marker labels: unexpected result** - Next by Date:
**st: AW: Interpretation of log transformed variables in logistic regression?** - Previous by thread:
**Re: st: Re: Bug in -use- or -if- ?** - Next by thread:
**st: Code to generate a difficult variable** - Index(es):

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