Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: Looping with -qreg-
From
"STANEVA A. (497186)" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: RE: Looping with -qreg-
Date
Thu, 19 Jan 2012 12:03:40 +0000
Thanks Nick for your comments.
I did try with constraint option but didn't get what I need. Basically my problem is to estimate the last qreg with the new constant term (u99) 'plug' in the model. There is not noncons option in qreg.
Best wishes
Anita
________________________________________
From: [email protected] [[email protected]] on behalf of Nick Cox [[email protected]]
Sent: 19 January 2012 11:52
To: [email protected]
Subject: Re: Looping with -qreg- [was: Re: st: Thread-Index: AczWnG9bfd8mYxtIRa2sdn3BOpo1xA==]
Also, it sounds as if you want to constrain your -qreg-, which makes
me feel queasy even contemplating the idea from a distance, but if so
that implies trying -constraint-.
Nick
On Thu, Jan 19, 2012 at 11:45 AM, Nick Cox <[email protected]> wrote:
> Please use informative titles (subjects) for your postings. Many
> people delete posts unread if they have weird titles.
>
> There are problems at various levels with your code.
>
> 1. The line
>
> local `b' = scalar(u99)
>
> looks like a mistake. If local b _was_ previously defined, then you
> need to refer to what this line defines as ``b''.
>
> 2. But you don't refer either to `b' or to ``b'' after defining it, so
> all you have done is defined something but never used it.
>
> 3. If local b was not previously defined, this line would not work.
> But that is not what you are reporting, so my guess is that a "local
> b" is defined earlier in your code.
>
> 4. If you have a scalar, there is no obvious need to put it into a
> local for what you want to do.
>
> 5. I don't understand what you want to do, but you are changing
> results, not instructions. Later runs of -qreg- pay no attention to
> e(b) produced by earlier runs of -qreg-.
>
> 6. -matrix b- and -local b- are completely different entities.
>
> Nick
>
> On Thu, Jan 19, 2012 at 11:21 AM, STANEVA A. (497186)
> <[email protected]> wrote:
>
>> Can someone help me with this loop in a qreg?
>> This first line works ok!
>>
>> forval i = 1/99 {
>> local q = `i'/100
>> quietly qreg $y $x if public==0, quantile(`q') nolog
>> matrix b = e(b)
>> matrix b[1, colnumb(b,"_cons")] = scalar(u99) /*I get the constant and replace it with the scalar u99, that I want/
>> }
>>
>> The problem comes here. I want the replaced u99 to be included in my qreg and then to get the predictions based on that regression:
>>
>> forval i = 1/99 {
>> local q = `i'/100
>> local `b’= scalar (u99)
>> quietly qreg $y $x if public==0, quantile (`q') nolog
>> predict xb if public==0
>> preserve
>> keep if xb~=.
>> restore
>> }
>> However, there is a problem in the line local`b'=scalar(u99), it seems stata doesn’t replace the _cons with the u99. It runs normal qreg, ignoring all this manipulations.
>>
*
* 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/
*
* 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/