*! v.1.0.0. N.Orsini, M Bottai 22oct2015 capture program drop xtqreg program xtqreg, eclass properties(mi) byable(onecall) version 13 if _by() { local BY `"by `_byvars'`_byrc0':"' } `version' `BY' _vce_parserun xtqreg, mark(OFFset CLuster) : `0' if "`s(exit)'" != "" { version 10: ereturn local cmdline `"xtqreg `0'"' exit } if replay() { if ("`e(cmd)'"!="xtqreg") error 301 Replay `0' } else `version' `BY' Estimate `0' end capture program drop Estimate version 12, missing program Estimate, eclass byable(recall) syntax varlist [if] [in] /// [, Level(integer $S_level) /// Quantiles(numlist) /// Random(string) /// Reps(string) /// SEED(string) /// Method(string) /// COVariance(string) /// NOConstant /// pathr(string) /// * ] local cmdline : copy local 0 preserve marksample touse // Get the panel variable from xtset or tsset capture quietly xtset if _rc != 0 { di as err _n "panel variable not set; xtset or tsset the data" exit 198 } local group `r(panelvar)' tempvar uniquev qui by `touse' `group', sort: gen `uniquev' = _n==1 qui replace `uniquev' = sum(`uniquev') if `touse' qui sum `uniquev' if `touse', meanonly local ngroups = r(max) // Check specified quantiles tempname quantlist SetQ `quantiles' local listquant "`r(quants)'" tokenize "`r(quants)'" local nq 1 while "``nq''" != "" { if (`nq' == 1) { mat `quantlist' = ``nq'' local listqr "c(``nq''" } else { mat `quantlist' = (`quantlist' , ``nq'') local listqr "`listqr', ``nq''" } local q`nq' ``nq'' local nq = `nq' + 1 } local nq = `nq' - 1 local listqr "`listqr')" // set the seed if "`seed'" != "" { set seed `seed' } local seed `c(seed)' // Check number of bootstrap replications // Set asymptotic variance estimator as default if "`reps'" == "" { local nreps = 20 } else { if `reps'<2 { di as err "specify more than 2 replications" exit } local nreps = `reps' } // Check number of observations quietly count if `touse' if r(N)<4 { di in red "insufficient observations" exit 2001 } // Remove collinear variables gettoken depv indepv : varlist _rmcoll `indepv' [`weight'`exp'] local indepv `r(varlist)' qui regress `depv' `indepv' if `touse' local nobs `e(N)' tokenize "`indepv'" local i 1 while "``i''" != "" { if _se[``i''] == 0 { di in blu /* */ "note: ``i'' dropped because of collinearity" local `i' " " } local i = `i' + 1 } // Check random effects _rmcoll `random' [`weight'`exp'] local randomeff `r(varlist)' foreach v of local randomeff { if regexm("`indepv'", "`v'") != 1 { di as err "specify a random effect that is included in the fixed effect" exit 198 } } // Check quantiles and get a list local pow = 10 local done = 0 while !`done' { local pow = `pow'*10 local done = 1 forvalues k=1/`nq' { local q = (`q`k'')*`pow' local done = `done' & (reldif(`q',trunc(`q')) | # [,] # ... */ , rclass version 6.0 if "`*'"=="" { ret local quants ".5" exit } local orig "`*'" tokenize "`*'", parse(" ,") while "`1'" != "" { FixNumb "`orig'" `1' ret local quants "`return(quants)' `r(q)'" mac shift if "`1'"=="," { mac shift } } end capture program drop FixNumb program define FixNumb /* # */ , rclass version 6.0 local orig "`1'" mac shift capture confirm number `1' if _rc { Invalid "`orig'" "`1' not a number" } if `1' >= 1 { ret local q = `1'/100 } else ret local q `1' if `return(q)'<=0 | `return(q)'>=1 { Invalid "`orig'" "`return(q)' out of range" } end capture program drop Invalid program define Invalid /* "" "" */ version 6.0 di in red "quantiles(`1') invalid" if "`2'" != "" { di in red "`2'" } exit 198 end capture program drop PrForm program define PrForm /* # */ , rclass local aa : di %8.2f `1' ret local pr `aa' if substr("`return(pr)'",1,1)=="0" { ret local pr = substr("`return(pr)'",2,.) } end exit use http://www.imm.ki.se/biostatistics/data/wtloss, clear reshape long y, i(id) j(month) gen inter = month*prog xtset id month * 1. Set the R path once for all global Rterm_path "C:\Program Files\R\R-3.1.1\bin\R.exe" xtqreg y prog month exit set trace off xtqreg y prog month exit xtqreg y prog month inter , q(25 75) pathr("/usr/bin/r") * 2. Set the R path as option xtqreg y prog month , pathr("/usr/bin/r") //pathr("C:\Program Files\R\R-3.1.3\bin\R.exe")