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]

Looping with -qreg- [was: Re: st: Thread-Index: AczWnG9bfd8mYxtIRa2sdn3BOpo1xA==]


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Looping with -qreg- [was: Re: st: Thread-Index: AczWnG9bfd8mYxtIRa2sdn3BOpo1xA==]
Date   Thu, 19 Jan 2012 11:45:45 +0000

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/


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