/************************************************************************/ /* qcrstep.ado */ /* Another censored quantile regression program */ /* for STATA 6.0 (see qcenreg.ado) */ /* by Robert Vigfusson */ /* Northwestern University */ /* 20 August 1999 */ /* */ /************************************************************************/ * WARNING: This program is offered without any guarantees. * Please send any comments by email to r-vigfusson@nwu.edu /************************************************************************/ * syntax similar to the qreq procedure. * QCRSTEP DEPVAR EXPVAR, QUANTILE QSTART QSTEP MAXITER MINCHNG * DEPVAR is the dependent variable * EXPVAR is the explanatory variables * QUANTILE is the quantile to be estimated. The default quantile is the median * QSTART is the quantile to be used to generate an intial starting value * QSTEP is the value by which you step between QSTART and QUANTILE. *The next options determine when the program will stop. * MINCHNG if there is this many or less changes in the estimated sample we assume convergence default 0 * MAXITER is the maximum number of attempted estimation iterations. default 100 /* Program Description: This program is for bottom censored data. For top censored data, the modifications to the code are described in comment lines beside the code. (Do a find for the word TOP to find the comments.) The estimation method is an iterative process based on Buchinsky (1991,1994). First estimate an unrestricted qauntile regression. Based on this estimate exclude those observations which have a predicted value of the quantile below the censoring point. On this reduced sample, re-estimate the quantile regression. Again exclude the observations that have predicted values below the censoring point. Repeat until your estimate converges. Convergence is defined in two ways here. The first is to say the estimate has converged when there is no further change in which observations that are excluded. This however may not always happen. Therefore, I also define convergence when I reach a maximum number of iterations. NOTE: If your quantile is too close to the censoring point, the entire data set could be excluded. The program therefore checks to insure that at least one percent of the observations are used in the restricted sample. If not, the program will only give a warning message and only estimate a normal quantile regression. */ program define qcrstep version 6.0 syntax varlist(min=1) [if] [, QUANtile(real 0.5) QSTART(real 0.5) QSTEP(real 0.01) MAXITer(integer 100) MINCHng(integer 0) ] tempvar prehat drpvold drpval cmpz cenzor valsamp numobz if `quantil' > `qstart' { * change inequality sign for top censored beep disp in red "ERROR" in green "Estimated Quantile `quantil' larger than Starting Value `qstart'" exit } tokenize `varlist' local depvar `1' mac shift local expvar `*' egen `cenzor' = min( `depvar' ) * If top replace this line with egen `cenzor' = max( `depvar' ) quietly qcenreg `varlist', quantile(`qstart') maxiter(`maxiter') minchng(`minchng') predict `prehat' gen `drpvold' = `prehat' > `cenzor' local qstart = `qstart' - `qstep' egen `valsamp' = sum( `drpvold') egen `numobz' = count(`depvar') while `qstart' > `quantil' & `valsamp'/`numobz' > 0.01 { quietly qcenreg `varlist' if `drpvold', quantile(`qstart') maxiter(`maxiter') minchng(`minchng') drop `prehat' predict `prehat' replace `drpvold' = `prehat' > `cenzor' local qstart = `qstart' - `qstep' drop `valsamp' drop `numobz' egen `valsamp' = sum( `drpvold') egen `numobz' = count(`depvar') } if `valsamp'/`numobz' > 0.01 { qcenreg `varlist' if `drpvold', quantile(`quantil') maxiter(`maxiter') minchng(`minchng') } else qcenreg `varlist', quantile(`quantil') maxiter(`maxiter') minchng(`minchng') end