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

st: RE: local variable


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: local variable
Date   Tue, 30 Sep 2003 15:59:59 +0100

JAYESH KUMAR

> I am tring to use some local varibales in a regreession model.
> For example,
> 
> su yvar,detail
> local a1=r(p1)
> local a2=r(p99)
> reg yvar xvar if yvar>`a1' & yvar<`a99' *Eq.1
> 
> su yvar, detail
> reg yvar xvar if yvar>r(p1) & yvar<r(p99) *Eq.2
> 
> Now the problem is when I am estimating Eq.1, it uses the criteria
> yvar>=`a1'&yvar<=`a99' rather than expected.It uses the 
> 5119 observations,
> while it should be 5118.
> 
> Eq.2 is not estimated, it gives the error of no observation.
> But the
> 
> su yvar,detail
> su yvar if yvar>r(p1)&yvar<r(p99)
> 
> shows that I have 5118 observations.
> and su yvar if yvar>`a1' & yvar<`a99' shows that I have 
> 5119 observations.
> 
> Is there any problem with declaration of local variable? 
> What are the
> otherways in wihich I can restrict my sample to be between 
> 1% and 99% of yvar?

My guess is that this is at root a precision 
problem. Your assignment of r(p1) 
and r(p99) to local macros isn't 
guaranteed to keep all the digits 
in the originals. After all, it's 
in essence both a numeric to string conversion 
and a change from binary representation to 
decimal representation all in one. I'd do it like this, 
cutting out all the locals: 

su yvar, detail
gen insample = yvar > r(p1) & yvar < r(p99) 
reg yvar xvar if insample

(Actually, if this were my problem, I would 
use -qreg-, as I dislike all outlier-dropping 
tricks like this, unless the outliers 
are definitely wrong in some strong sense.) 

Nick 
[email protected] 

P.S. "local variable" is your own terminology. 
"local macro" or "local" is Stata's. Best to 
use Stata's. 

*
*   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