Bookmark and Share

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]

RE: st: RE: Looping with -qreg-


From   "STANEVA A. (497186)" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: RE: Looping with -qreg-
Date   Thu, 19 Jan 2012 14:22:31 +0000

The intercept should be different of course; I haven't copy this bit of the code, as I think is working ok.  I defined it by every percentile in the following way following someone in the literature:

forval i = 1/99 {
 local q = `i'/100 /* quantile to be estimated */
 quietly qreg $y $x if public==0, quantile(`q') nolog 
 predict uresid, resid
 preserve
 keep if uresid~=. /* keep valid predictions */
 keep uresid /* throw away other vars */
 save uresid`i', replace
 restore
 scalar u99=sum(ws_g99*uresid) /*derive the intercept by every percentile, ws_g99 is the weights of each individual residual defined in my sample*/
 drop uresid
}

I’m not quite sure how the constraint option works. I did try to constraint the qreg by defining the constraint being u99.

constraint define 1 [_cons]_cons=`u99'
    if `"`constraint'"'!="" {
    quietly qreg $y $x psm1 psm2 if `constraint (1)' & public==0, quantile(`q') nolog 
    predict xb if public==0 
However, the syntax wasn’t seems to be correct. 
It is a bit complicated, so I really will appreciate your help.
Best 
Anita


________________________________________
From: [email protected] [[email protected]] on behalf of Nick Cox [[email protected]]
Sent: 19 January 2012 13:59
To: [email protected]
Subject: Re: st: RE: Looping with -qreg-

So it seems you want a set of quantile regressions for fractions 0.01
(0.01)0.99 but with the same intercept. Wow!

I would suggest being clearer on what you tried with -constraint- and
why it didn't solve the problem.

Nick

On 19 Jan 2012, at 12:03, "STANEVA A. (497186)" <[email protected]
 > wrote:

> 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] [owner-
> [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 norm
>>> al 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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index