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]

st: RE: moptimize routine that works with quantile regression?


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: moptimize routine that works with quantile regression?
Date   Mon, 17 Jan 2011 18:11:55 +0000

I don't have an answer to your main question, but I have three marginal observations. 

1. It's debatable if not dangerous style to refer to Stata local macros deep within Mata code. Far, far better to pass their value to Mata as an argument of your function. 

2. Assuming 1., 

for (i=1; i<=rows(y); i++) {
if (y[i,1]-p[i,1] > 0) {
mult[i,1] = `quart'
}
else {
mult[i,1] = 1-`quart'
}
}

looks as if it could be rewritten without a loop and repeated testing: 

mult[,1] = ((y[,1] - p[,1]) :> 0) :* quart  +  ((y[,1] - p[,1]) :<= 0) :* (1 - quart) 

The pedestrian idea here is that you mimic an elementwise conditional operator by 

(1 if true, 0 if false) :* (what you want if true)   
+ 
(1 if false, 0 if true) :* (what you want if false) 

Whether mult, y, p should be separate column vectors I can't say. 

3. Didn't Newton come first? 

Nick 
[email protected] 

Tatyana Deryugina

I'm trying to program a quantile regression algorithm in mata, using
the moptimize() routine. However, I'm having trouble finding an
evaluator + technique that leads to convergence. I've read that the
Frisch-Newton optimization method is fast and appropriate for quantile
regression - are there any Mata routines (within moptimize or
otherwise) that implement this?
Here's the way I'm constructing the objective function (or the vector
that moptimize will sum):

for (i=1; i<=rows(y); i++) {
if (y[i,1]-p[i,1] > 0) {
mult[i,1] = `quart'
}
else {
mult[i,1] = 1-`quart'
}
}
lnf = mult:*abs(y:-p)
}

y is the dependent variable, p is Xb, lnf is the "likelihood" vector,
and `quart' is the quartile. I tell moptimize to minimize this
"likelihood".
I've tried the "lf" and "gf0" evaluators and pretty much all the
optimization techniques. In some cases (when there are few independent
variables), I get the right answer, but for 4 dependent variables, the
routine doesn't work.
The reason I'm not using Stata's built-in command is because I
ultimately want to bootstrap the standard errors as well as use
weights. I've also found qreg and bsqreg to be very slow in my case
(lots of observations and dependent variables).


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