Saturday, 28 March 2015

Quantile Regression using STATA


Why Quantile Regression?
  1. Provides more complete picture on relationship between Y and X: it allows us to study the impact of independent variables on different quantiles of the dependent variable. Normal regression is based on mean of Y.
  2. Robust to outliers in Y observations.
  3. Estimation and inferences are distribution-free.

Application of Quantile Regression using Stata:

* If you haven't installed the estout package yet, run: ssc install grqreg, replace
* If you are not sure, then go to Help -> Stata Command -> type grqreg.
* If says 'Not Found', then you need to install it.

* 1. Import the data:
    use https://dl.dropboxusercontent.com/u/18255955/PhD-INCEIF/QR%20Data_Tutorial.dta, clear

* 2. Specify dependent and independent variables:
global ylist LRY
global xlist LRV INT LRC LVS LGS

* 3. To get summary statistics about the data:
summarize $ylist $xlist

* 4. To run normal regression:
reg $ylist $xlist

* 5. To test heteroscedasticity:
estat hettest $xlist, iid

* 6. To run Quantile regression (50%):
qreg $ylist $xlist, quantile(0.5)

* 7. To plot Quantile regression and Normal regression with confidence intervals:
grqreg, cons ci ols olsci

* 8. To get the results for more than one quantile:
  sqreg $ylist $xlist, quantiles(5 10 15 25 40 50 60 75 85 90 95) reps(20)

* 9. To test whether estimates for quantiles are same:
test[q25]INT = [q75]INT


Tips: Tabulation of data for publication

* 1. Install package (only for the first time): 
ssc install estout, replace

* 2. Run OLS and store the results in memory: 
quietly reg $ylist $xlist
eststo OLS_res

* 3. Run Quantile regression for 0.25 percentile and store the results: 
quietly qreg $ylist $xlist, quantile(25)
eststo Q25_res

* 4. Run Quantile regression for 0.50 percentile and store the results: 
quietly qreg $ylist $xlist, quantile(50)
eststo Q50_res

* 5. Run Quantile regression for 0.75 percentile and store the results: 
quietly qreg $ylist $xlist, quantile(75)
eststo Q75_res

* 6. To tabulate the results: 
estout *, cells(b(star fmt(3)) se(par fmt(3))) legend

or

esttab OLS_res Q25_res Q50_res Q75_res,  star(+ 0.1 * 0.05 ** 0.01) mtitle(OLS QR25 QR50 QR75)  b(%9.3f) se(%9.3f) bracket nonum compress