Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Qreg on Multiple Iterations of Data

From   Maarten Buis <>
Subject   Re: st: Qreg on Multiple Iterations of Data
Date   Mon, 28 Oct 2013 09:54:30 +0100

On Sun, Oct 27, 2013 at 10:03 PM, cerulean 74 wrote:
> I'd like to use quantile regression for 1000 iterations on 100
> observations: my data consists of values for three variables: Y, X1,
> and X0(just a column vector of 1's). Each variable has 1000 columns of
> values (each column is an iteration) and 100 rows(each row is an
> observation). The goal is to use qreg to obtain 1000 coefficients of
> X1, and 1000 coefficients of X0, output to Excel as two column vectors
> of coefficients. That is, I would like to regress each column of Y on
> the corresponding column of X and X0, a thousand times. I've tried
> both STATA and MATA: my version of STATA has a maximum matrix size of
> 800, whereas my overall dataset size is 100 by 2001, and MATA does not
> have a qreg option. Any advice/tips on how to achieve this? Thanks!

Please sign your post to Statalist with your real name. Other forums
have different standards, but this is the standard used on this forum
as you could and should have read on the Statalist FAQ:

Also, there are no such things as STATA or MATA. However, Stata and
Mata do exist, so I assumed you mean those programs. See the Statalist
FAQ for an explanation:

You can ignore X0, as Stata will by default already include a
constant. You can use the -post- command to store the results, which
will have no problem with a thousand iterations.

*------------------ begin example ------------------
// create some example data
drop _all
set obs 100
forvalues i = 1/10 {
    gen x`i' = rnormal()
    gen y`i' = 1 + 2*x`i' + rnormal(0,.5)

// estimate the -qreg-s and store the results
tempname memhold
tempfile results
postfile `memhold' b1 b0 using `results'
forvalues i = 1/10 {
    qreg y`i' x`i'
    post `memhold' (_b[x`i']) (_b[_cons])
postclose `memhold'
use `results', clear
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* )

However I will presume your thousand iterations are the results of a
simulation. In that case it is more efficient to do this differently:

*------------------ begin example ------------------
clear all

program define sim
    drop _all
    set obs 100
    gen x = rnormal()
    gen y = 1 + 2*x + rnormal(0,.5)
    qreg y x

simulate _b, reps(10) : sim
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* )

Hope this helps,

Maarten L. Buis
Reichpietschufer 50
10785 Berlin
*   For searches and help try:

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