Stata Code

Last updated: 15th January 2018 (WAITING TO BE UPDATED ON THIS NEW GOOGLE SITE)

NEW Empirical Development Economics is now published and available from standard retailers. Data and do-files are available here: www.empiricalde.com.

NEW The xtcaec command written by Korbinian Nagel

NEW The xtmg3 command written by Maximo Sangiácomo

NEW The xtgcause command written by Lopez and Weber

NEW The xtcdf command written by Jesse Wursten (v2017)

NEW The xtcointreg command written by Rav Khodzhimatov

Please see help files for examples, data links, references and acknowledgements. For a wealth of data sources for development economics please refer to my data website. Empirical illustrations using the below routines can be found in my own research papers. For an introduction to the panel time series field see my presentation at the Stata UK User Group Meeting.

The usual disclaimers apply. Note that I am unable to provide detailed comments or explanations on the code written by others: please take it up with the authors. For feedback or new commands please email me at markus.eberhardt@nottingham.ac.uk.

My Panel Time Series commands

xtmg

Estimating panel time series models with heterogeneous slopes - ado, help, Stata Journal article, application

Version: 1.0.2 - 4th January 2012 - in Stata: -ssc install xtmg- (Using SSC will get you the previous version for the time being; use the above download links for the latest version)

This command implements the Pesaran and Smith (1995) Mean Group (MG) estimator, the Pesaran (2006) Common Correlated Effects Mean Group (CCEMG) estimator and the Augmented Mean Group (AMG) estimator introduced here and discussed and tested here. For these macro panel estimators the cross-panel average estimates can be reported as unweighted or outlier-robust means, where the latter is implemented via the rreg command. Optionally the routine reports the group-specific regression results and produces residuals and predicted values based on these. The example in the helpfile links to a dataset (+ related working paper) and goes through all the options of the command. This code is applied in our REStat paper on R&D spillovers. Other illustrations with data (including a Stata Journal article) can be found here.

multipurt

Investigating variable nonstationarity in macro panels - ado, help

Version: 1.0.1 - 8th February 2011 - in Stata: -ssc install multipurt-

This command runs the Maddala and Wu (1999) as well as the Pesaran (2007) panel unit root tests for multiple variables and lags. This is not a new command for these panel unit root tests but a convenient tool using the existing xtfisher and pescadf commands written by Scott Merryman and Piotr Lewandowski respectively (both commands need to be installed for multipurt to work). In the future this will hopefully also include the CIPSM panel unit root test by Pesaran, Smith and Yamagata (2009). The example in the helpfile links to a dataset (+ related working paper) and goes through all the options of the command. Further illustrations with data can be found here.

xtcd

Investigating variable and residual cross-section dependence in macro panels - ado, help

Version: 1.0.0 - 5th February 2011

This command implements the Pesaran (2004) CD test for cross-section dependence in panel time-series data. The routine builds on the xtcsd command by De Hoyos and Sarafidis (2006) but is not a post-estimation command: xtcd can be applied to variables as well as to residuals, provided the latter have been previously computed as a separate variable series (using for instance the xtmg command). Furthermore, in the multipurt spirit up to 9 variable or residuals series can be tested together. Further illustrations with data can be found here. The Pesaran (2015, Econometrics Reviews) paper shows that the CD test is really a test for weak cross-section dependence rather than independence.

Please note: This version and the one on SSC has a bug whereby the average number of observations per correlation as well as the balancedness/unbalancedness of the panel are wrong. This will be corrected in the forthcoming Mata version of the routine.

NEW July 2017: Jesse Wursten at KU Leuven has re-written the xtcd command so that it is much faster when using the 'resid' option. Download his xtcdf ado file here. This is now also available on SSC. (Usual disclaimers apply)

xtectest (incomplete)

Investigating heterogeneous panel cointegration with an error correction test - ado-file, help-file

Version: 0.0.0

This command implements the error correction based cointegration test by Gengenbach, Urbain and Westerlund (2009), which builds on earlier work by Westerlund (2007). The test investigates error correction at the group-level (e.g. country) and can account for cross-section dependence. A rough an ready approach is described here.

xtcipsm (incomplete)

Investigating variable nonstationarity in macro panels with multiple unobserved factors - ado-file, help-file

Version: 0.0.0

This command implements the Pesaran, Smith and Yamagata (2009) panel unit root test. It extends the cross sectionally augmented panel unit root test proposed by Pesaran (2007) to the case of a multifactor error structure. The basic idea is to exploit information regarding the unobserved factors that are shared by other time series in addition to the variable under consideration. The test procedure only requires specification of the maximum number of factors, in contrast to other panel unit root tests based on principal components that require in addition the estimation of the number of factors as well as the factors themselves. A rough an ready approach is described here.

xtbcis (incomplete)

Testing for Panel Cointegration Using Common Correlated Effects Estimators - ado-file, help-file

Version: 0.0.0

This commands implements the panel cointegration test by Banerjee and Carrion-i-Silvestre (2011). This runs a standard CIPS panel unit root test on some 'residuals' from a Pesaran (2006) CCEP model. A rough an ready approach is described here.

Panel Time Series Tools coded by others

Useful tools (not just for macro panels)

* Nick Cox has written xtpatternvar which gives you insights into the unbalancedness of the panel and which observations are missing. Missing observations are a common feature of macro panel data, so maybe also have a look at the paper by Ron Smith and Ali Tasiran on 'Random coefficients models of arms imports' in Economic Modelling, 2010, Vol.27(6).

Panel Unit Root Testing (PURT)

* The Breitung (2000) panel unit root/stationarity test (xtunitroot breitung) is implemented in Stata 11; requires a strongly balanced panel. Note that the help file for xtunitroot provides a nice overview of all the tests.

* The Hadri (2000) panel unit root/stationarity test (xtunitroot hadri) is implemented in Stata 11; requires a strongly balanced panel. Prior to this version you can use the command written by Kit Baum (hadrilm).

* The Harris & Tzavalis (1999) panel unit root/stationarity test (xtunitroot ht) is implemented in Stata 11; requires a balanced panel.

* The Im, Pesaran & Shin (1997, 2003) panel unit root/stationarity test (ipshin) was coded by Fabian Bornhorst and Kit Baum; country series cannot have gaps. This is also implement in Stata 11 (xtunitroot ips).

* The Levin, Lin & Chu (1992, 2002) panel unit root/stationarity test (levinlin) was coded by Fabian Bornhorst and Kit Baum; country series cannot have gaps. This is also implement in Stata 11 (xtunitroot llc).

* The Maddala & Wu (1999) panel unit root/stationarity test (xtfisher) was coded by Scott Merryman. The option 'pp' implements the Phillips and Perron (1988) test at the country-level instead. Both of these options are also implement in Stata 11 (xtunitroot fisher).

* The Pesaran (2006) CIPS panel unit root/stationarity test (pescadf) was coded by Piotr Lewandowski.

* Simon Reese has coded the Bai and Ng (2004) PANIC PURT along with his own Westerlund and Reese (2016) PANICCA PURT, which can be downloaded as command xtpanicca from here. All enquiries (and praise) please directly to Simon at USC Dornsife.

* Burdisso and Sangiacomo have written the xtcips command and discuss it in a recent Stata Journal article. This can be downloaded from within Stata by typing 'ssc install xtcips'.

Cointegration Testing

* The seven Pedroni (1999) residual based cointegration tests (first generation, i.e. limited allowance made for cross-section dependence, unless you assume [getting technical] that the unobservables are identical in thei impact across countries) was recently coded by Timothy Neal of UNSW as xtpedroni (link is for the Stata Journal article [subscription required], but of course you can install xtpedroni from within Stata by typing - findit xtpedroni -). Consult the help files in Stata after installation for further details. Tim's got a nice paper in the Economic Record (subscription required) where he applies these and the estimators also included in the routine (see below).

* The Westerlund (2007) error-correction/cointegration test (xtwest) was coded by Damiaan Persyn; it requires that the country series do not have gaps but as a very useful feature tells the user which country series violate this requirement.

Granger (Non-)Causality Testing

* NEW The xtgcause command written by Luciano Lopez and Sylvain Weber (both at the University of Neuchâtel) carries out a test for Granger non-causality in heterogeneous panels based on an Economic Modelling paper by Elena-Ivona Dumitrescu and Christophe Hurlin.

Cross-section Dependence Testing

* The Pesaran (2004) CD test for cross-section dependence was coded by Rafael E. De Hoyos and Vasilis Sarafidis (xtcsd). This command operates as a post-estimation command following xtreg, fe or re. See xtcd above for a more flexible procedure. The Pesaran (2015, Econometrics Reviews) paper shows that the CD test is really a test for weak cross-section dependence rather than independence.

* Burdisso and Sangiacomo have written the xtcsi command for the Pesaran (2004/2015) CD test and discuss it in a recent Stata Journal article (Volume 16, Issue 2, 2016). This can be downloaded from within Stata by typing 'ssc install xtcsi'. This command also covers the Breusch and Pagan (1980) LM test as well as the adjusted LM by Pesaran, Ullah, and Yamagata (2008). Unfortunately, the command requires a balanced panel, so you might be better off using my xtcd after all...

* A number of tools for spatial econometric analysis including Moran's (1950) I statistic were written by Maurizio Pisati (this covers a number of commands, most conveniently found via -findit spatial- or for a description the Stata Bulletin 60, sg162). A new set of spatial estimators for Stata (spmlreg) has been developed by P. Wilner Jeanty, with David Drukker et al also chipping in rather substantially for cross-section analysis (sppack). Note that for all spatial econometric analysis it is required that you specify a spatial weight matrix. The Pisati commands allow you to do so provided you have relevant data.

Spatial Econometric Methods

* A number of tools for spatial econometric analysis including Moran's (1950) I statistic were written by Maurizio Pisati (this covers a number of commands, most conveniently found via -findit spatial-; for a description see Stata Bulletin 60, sg162, free access). A new set of spatial estimators for Stata (spmlreg) has recently been created by P. Wilner Jeanty, with Stata's David Drukker et al also chipping in rather substantially for cross-section analysis (sppack). Note that for all spatial econometric analysis it is required that you specify a spatial weight matrix. The Pisati commands allow you to do so provided you have relevant data. Further spatial commands in Stata include spagg (something to do with dyadic data), spautoc (Moran and Geary measures of spatial correlation), spgrid (creating two-dimensional grids), sphdist (spherical distance), splagvar (create spatial lags and other tools), spmon (monadic data), spseudor2 (create measure for goodness-of-fit), spspc and spundir (more dyadic data tools), spwmatfill and spwmatrix (tools for creation/import/export of spatial weight matrices). Franzese, Hays and Kachi (2010) also have code for their m-star estimator (multiparametric spatiotemporal autoregressive model).

* There are some new resources for spatial econometrics provided in the form of a talk by Maurizio Pisati at the 2012 German Stata Users Group, as well as two talks to be given at the Spanish Stata User Group meeting later this year (September 2012). In general it's worth your time looking through the materials for past meetings.

* Tim Conley at Western Ontario provides detailed code for his work on GMM estimation with cross-sectional dependence.

The cross-section version of the aforementioned m-star estimator has also been coded by Emad Abd Elmessih Shehata and Sahra Khaleel A. Mickaiel in form of the spmstardh command, and by the former author for the panel in form of the spmstarxt command.

* Federico Belotti, Gordon Hughes and Andrea Piano Mortari have created a suite of fixed and random-effects spatial models for balanced panel data in form of the xsmle command. This includes Spatial Autoregressive Model (SAR), Spatial Error Model (SEM), Spatial Durbin Model (SDM), Spatial Autoregressive Model with Autoregressive Disturbances (SAC), Generalized Spatial Random-effects Model (GSPRE). The command can compute direct, indirect and total spatial effects (LeSage, 2008) and can also transform the data to accommodate fixed effects. With the -mi- prefix command this estimator can also be used for unbalanced panels.

* Marinho Bertanha and Petra Moser have developed a methodology to allow for spatial dependence (defined via a weight matrix/coordinates) in the analysis of count data. Their paper 'Spatial Errors in Count Data Regressions' is available here, Stata and Matlab code can be downloaded as well.

Panel Time Series Estimators

* The Kao & Chiang (2000) Dynamic OLS (DOLS) estimator for Cointegrated Panel Data with homogeneous covariance structure was recently coded in Stata by Diallo Ibrahima Amadou (CERDI) as xtdolshm; you will also need to install ltimbimata. Both can be found via -ssc install- or -findit- in Stata. Make sure you have the latest version of this command, since Diallo has recently ironed out a bug related to the computation of the confidence intervals. Also: email him rather than me if you have any questions about this command!

* The Swamy (1970) Random Coefficient Model (RCM) estimator is implemented in Stata (xtrc). The special edition of Economic Modelling on P.A.V.B Swamy should be useful for anybody using the RCM estimator: Volume 27, Issue 6, November 2010.

* Timothy Neal of UNSW has coded xtpedroni (link is for the Stata Journal article [subscription required], but of course you can install xtpedroni from within Stata by typing - findit xtpedroni -), which implements the Pedroni (2001) Group Mean DOLS estimator. Tim's got a nice paper in the Economic Record (subscription required) where he applies this estimator.

NEW * Ravshanbek Khodzhimatov has extended the time series command cointreg to panel: xtcointreg allows for estimation of the panel versions of the DOLS, FMOLS and canonical regression models. The help file is vague/confusing as to whether these are 'Group Mean' or (pooled) 'panel' versions - I think the use of 'panel DOLS' etc. is wrong, given that the 'full' option allows for country-specific results, which wouldn't be possible in a pooled panel estimator...

* Tim Neal has also coded xtcce, which provides not just the static Pesaran (2006) CCE estimator but also the dynamic version(s) (Chudik and Pesaran, 2015) as well as IV/GMM-versions Tim developed as part of his PhD. Although we did not use Tim's code as part of the empirics for the paper (all the data and code are provided at the below link), an application of the dynamic CCE can be found in my recent JIE paper on debt and growth with Andrea Presbitero (IMF).

* Jan Ditzen at Hariott-Watt in Edinburgh has coded an alternative version of the static Pesaran (2006) CCE estimator alongside the dynamic version(s) (Chudik and Pesaran, 2015) which he christened xtdcce. This can be used as an alternative to Tim Neal's code above, since it provides similar functionality (though it automatically adds Pesaran (2015) CD test results). A working paper discussing the command(s) is here.

NEW * The xtcaec command written by Korbinian Nagel at Hamburg's Helmut Schmidt University is a wrapper for xtmg and xtcd2 which computes error correction models, presenting mean group long-run coefficients as the outcome. Oh, and of course the point is that this routine allows for strong cross-section dependence of the strong type (it also tests the residuals for weak vs strong dependence). Thus it implements the Chudik and Pesaran (2015) dynamic CCE estimator. As the author kindly points out this is applied in my 2015 JIE paper with Andrea Presbitero (link to paper, data and code here).

* Matthieu Gomez of Princeton has coded regife, which implements the Bai (2009) interactive fixed effects estimator (also available from SSC: ssc install regife). The estimator (and Matthieu's command) allows for unbalanced panels as is outlined in the Supplementary appendix of the Bai (2009) paper. To the best of my knowledge this is the first time one of the various estimators which compute factors and factor loadings as part of the estimation procedure has been coded in Stata. A nice application of this estimator is on regional policy evaluation in a recent REStat paper by Gobillon and Magnac (2016, Volume 98, Issue 3 - WP version is here). These guys estimate things in R and provide all the data and code.

NEW * Maximo Sangiácomo from the Central Bank of Argentina has written a neat extension for the standard Pesaran (2006) CCE estimator command xtmg: if you want to include one or more observed common factor(s) in your model (along with the cross-section averages of all other model variables to capture unobserved common factors), then you can use xtmg3 with the options 'cce' and 'excl(varlist)' - you specify in the latter for which variables you do not want cross-section averages included. This means you can now for instance include the Brent Crude oil price in your cross-country analysis.

* The ever-inventive Tim Neal of UNSW has created a new estimator and associated routine (xtmo) for static and dynamic panel time series models that feature intercept and slope heterogeneity across both the time-series and cross-section dimensions. For now this approach assumes cross-section independence (so like the Pesaran and Smith, 1995, MG estimator). The above link to xtmo provides a zipped folder which also include the working paper for this new approach.