Program Code

download Program Code

If you can't read please download the document

description

code for estimating bekk

Transcript of Program Code

*! xtvar.ado v1.0.2 Cagala & Glogowsky 01apr2015*! Friedrich-Alexander Universitt Erlangen-Nuremberg*! For an application see Cagala et al. (2014): Cooperation and Trustworthiness in Repeated Interaction*! For Stata 12.0+* Version history* 1.0.1* 1.0.2capture program drop xtvarprogram xtvar, eclassversion 12.0 //program is for STATA 12.0+eret clearsyntax varlist [if] [, ///LAGs(integer 2) ///Reps(integer 200) ///STep(integer 8) ///Level(integer 95) ///SSAving(string) ///POoled ///bsn ///dbsn ///bsp ///mc ///STIrf ///norm ///nodraw ///]/*set standard method for ci*/if "`bsn'`dbsn'`bsp'`mc'" == "" {local bsn = "bsn"}if length("`bsn'`dbsn'`bsp'`mc'") > 4 {di "{err}please select only one method for computing confidence intervals"exit `rc'}/*ERROR section*/*confirm variable names*while "`1'" != "" {if length("'1'") >= 3 {if strmatch("`1'", "cons") == 1{di "{err}input variables are not allowed to be named 'cons'"exit `rc'}if substr("`1'", 1, 3) == "l1_"{di "{err}input variables are not allowed to begin with 'l1_'"exit `rc'}}mac shift}*check if unbalanced panel*qui xtsetif r(balanced) != "strongly balanced"{di "{err}panel is not strongly balanced"exit `rc'}*check if there are gaps in time variable"qui tsreport, panelif r(N_gaps) != 0{di "{err}there are gaps in the time variable"exit `rc'}tempname depvar b V V_s txt1 txt2 txt3 ///panelvar timevar d cresv resv CI2 CI3 MSRpreservecapture noisily {/*allow for if statements*/if "`if'" != "" {quietly keep `if'}/*sort*/qui xtsetsort `r(panelvar)' `r(timevar)'/*new xtset*/local ivar "`r(panelvar)'"egen `panelvar' = group(`ivar')by `ivar': gen `timevar' = _nqui xtset `panelvar' `timevar'/*generate local macros*/local cmdline "`0'"local tmax `r(tmax)'local imax `r(imax)'local depvars = wordcount("`varlist'")local rep 0local step = `step' + 1if missing("`rm'") {local cit "p"}else {local cit "n"}/*generate lagged variables & dummies*/genlagdum `varlist' , /// d(`d') ///timevar(`timevar') ///panelvar(`panelvar') ///`pooled' ///lags(`lags')local obs = _N //number of observations/*generate lists*/lists `varlist' , ///d(`d') ///`pooled' ///lags(`lags') ///imax(`imax') ///rep(`rep')local indepvarlist "`r(indepvarlist)'"local constants "`r(constants)'"/*estimation*/estimation `varlist' , ///resv(`resv') ///cresv(`cresv') ///panelvar(`panelvar') ///ci(`bsn' `dbsn' `bsp' `mc') ///depvars(`depvars') ///lags(`lags') ///rep(`rep') ///indepvarlist(`indepvarlist') ///constants(`constants')local res`rep' "`r(res`rep')'"if (!missing("`bsn'") | !missing("`dbsn'")) & `rep' == 0 {local cres "`r(cres)'"}/*covariance matrix*/covariance , ///`pooled' ///depvars(`depvars') ///lags(`lags') ///imax(`imax') ///obs(`obs') ///rep(`rep') ///res(`res`rep'')/*contemporary effects*/contemporary , /// rep(`rep')/*variance coefficients*/varianceb `varlist' , ///rep(`rep') ///indepvarlist(`indepvarlist') ///constants(`constants') ///ci(`bsn' `dbsn' `bsp' `mc')/*irf*/irf , ///`stirf' ///lags(`lags') ///step(`step') ///rep(`rep') ///depvars(`depvars')mat drop COL`rep'tempfile boot/*generate variables/dataset*/if missing("`mc'") { keep `cres' `timevar' `panelvar'qui save "`boot'" //save dataset for bootestrap}/*fevd*/fevd , ///step(`step') ///rep(`rep') ///depvars(`depvars')local fevd "`r(fevd)'"/*prepare monte carlo*/if !missing("`mc'") {preparemc , ///`pooled' ///obs(`obs') ///reps(`reps') ///rep(`rep') ///depvars(`depvars') ///constants(`constants') ///indepvarlist(`indepvarlist') ///depvarlist(`varlist') ///lags(`lags') ///imax(`imax')local betau "`r(betau)'"}/*confidence intervals*/ci , ///resv(`resv') ///timevar(`timevar') ///panelvar(`panelvar') ///`stirf' ///`pooled' ///ci(`bsn' `dbsn' `bsp' `mc') ///step(`step') ///reps(`reps') ///obs(`obs') /// lags(`lags') ///imax(`imax') ///tmax(`tmax') ///level(`level') ///cres(`cres') ///depvars(`depvars') ///res0(`res0') ///constants(`constants') ///indepvarlist(`indepvarlist') ///betau(`betau') ///boot(`boot')/*results: matrices*/if missing("`pooled'") {mat `b'=vec(B_s0)'local i = 1 //drop rows with dummieswhile `i' 1 {mat `J' = I(`depvars'), J(`depvars', `lags' * `depvars' - `depvars',0)} else { mat `J' = I(`depvars')}/*companion matrix C*/if `lags' > 1 {mat `TEMP' = I(`lags' * `depvars' - `depvars'), ///J(`lags' * `depvars' - `depvars', `depvars', 0) mat `C' = B_s`rep'' \ `TEMP'}else {mat `C' = B_s`rep''}/*response matrix*/mat `AS' = I(`lags' * `depvars')/*IRF*/forvalues i = 1 / `step' {if missing("`stirf'") {mat `DS' = `J' * `AS' * `J'' * COL`rep'}else {mat `DS' = `J' * `AS' * `J'' * A`rep' }mat `DS' = vec(`DS')mat D`rep' = nullmat(D`rep') \ `DS''mat `AS' = `AS' * `C'}end//FEVDcapture program drop fevdprogram fevd, rclasssyntax [ , ///step(integer 8) ///depvars(integer 1) ///rep(string) ///ci(string) ///]tempname FEVD/*generate dataset*/qui svmat D`rep'qui keep if _n