This a a list of my Stata packages (for more details scroll down):



xtdcce2 and xtcd2 (GitHub)

xtcse2 (GitHub)

xtbreak (GitHub)

nwxtregress (GitHub)


simulate2 / psimulate2








xtgranger (on SSC, joint work with J. Xiao, A. Juoadis, Y. Karavias and V. Sarafidis)

xtgranger performs the Half-Panel Jackknife (HPJ) Wald-type test for Granger non-causality, developed by Juodis, Karavias, and Sarafidis (Empirical Economics, 2021). This test offers superior size and power performance, which stems from the use of a pooled estimator with a (NT)^(1/2) rate of convergence. The test has two other useful properties; it can be used in multivariate systems and it has power against both homogeneous as well as heterogeneous alternatives. The command also reports results for the HPJ estimator.

xtnumfac (on SSC, joint work with S. Reese)

xtnumfac estimates the number of common factors in panel datasets using the methods of Bai and Ng (2002), Ahn and Horenstein (2013) Onatski (2010) and Gagliardini et al. (2019). The methods in Bai and Ng (2002) are based on six information criteria, while Ahn and Horenstein (2013) propose two estimation methods. Onatski (2010) and Gagliardini et al. (2019) contribute a single estimator each.

xtdcce2 and xtcd2 (on SSC)

xtdcce2 estimates heterogeneous coefficient models using common correlated effects in a dynamic panel. xtcd2 tests for cross sectional dependence. Download and more infos are available here.

The latest version is available from within Stata: net install, from(


xtcse2 estimates the exponent of cross-sectional dependence in a panel with a large number of observations over time (T) and cross-sectional units (N). The estimation method follows Bailey, Kapetanios, Pesaran (2016). xtcse2 estimates the strength of the factor, for a residual or one or more variables. It outputs the point estimate, the standard error and confidence interval. It is intend to support the decision whether to include cross-sectional averages when using xtdcce2 and accompanies xtcd2 in testing for weak cross-sectional dependence. As a default it uses xtcd2 to test for weak cross-sectional dependence.

It is part of the xtdcce2 package. Download and more infos are available here.

The latest version is available from within Stata: net install, from(

nwxtregress (joint work with William Grieser and Morad Zekhnini)

Network Regressions in Stata with unbalanced panel data and time varying network structures or spatial weight matrices.

For the latest version see Github.

xtbreak (joint work with Yiannis Karavias and Joakim Westerlund)

xtbreak Estimation and testing of structural breaks in time series and panel data

Slides: Swiss UGM 2020, German UGM 2021, US Conference 2021

For the latest version see Github.


multishell allows the efficient processing of loops and of multiple do files across a single and multiple computers. multishell dissects forvalues and foreach loops and creates for each variation (tasks) a separate do file. The do files are queued and sequentially processed. Besides the do file, a .bat file is created for each task. Then Stata's build in shell command is used to start a new instance of Stata using the .bat file. The instance is closed as soon as the task is completed (or failed, then it is reported) and a new instance processing the next task is started. One instance is reserved to organise the tasks and starts other instances. Multiple instances can be run in parallel on the same computer.

Install from within Stata using: net from or ssc install multishell

See helpfile.

Slides for 2018 London Stata User Group Meeting.

xthst (joint work with Tore Bersvendsen , University of Agder)

xthst performs a test of slope homogeneity in panels with a large number observations of the cross-sectional (N) and time (T) dimension. The null hypothesis of the test is of homogenous slopes. This implies all slope coefficients are identical across cross-sectional units. The test is a standardized version of Swamey's test for slope homogeneity presented by Peasaran and Yamagata (2008).

Install from within Stata: net install xthst, from("") or ssc install xthst

simulate2 / psimulate2

simulate2 enhances Stata’s built-in simulate command. Simulate eases the programming task of performing Monte Carlo type simulations. By using frame post rather than postfile simulate2 allows programs to return strings (macros) to r() and e(). Results can be saved into frames and dtas. simulate2 has advanced facilities to save and assign seeds and seed streams to individual draws of the program called by simulate2. psimulate2 parallelises simulate2 and speeds up Monte Carlo type simulations. The number of replications are divided into blocks and each block is run on a separate instance of Stata.

Install from within Stata: net install simulate2, from("") or ssc install xthst

xtbalance2 (new - 30.01.2021)

xtbalance2 creates a balanced subsample from an unbalanced dataset. xtbalance2 does not drop any observations, it creates a variable indicating if an observations (or row) is part of the balanced subsample. xtbalance2 tries to maximise either the number of cross-sectional units (ids), time periods or total number of observations. To do so it uses a simple algorithm which finds the largest subsquare in a matrix. Theoretically it is possible to obtain more than one solution to the maximisation problem. In this case xtbalance2 creates an indicator variable for each solution.

Install from within Stata: net from or ssc install xtbalance2


Downloads trade data from UN Comtrade using jsonio and parses the output in a user friendly format.

comtrade downloads trade data from UN Comtrade. Comtrade trade data is available in the JSON (JavaScript Object Notation) format. comtrade uses the user written command jsonio to download the data in the JSON format, it then parses the retrieved data bringing it in into an user friendly format. Comtrade offers data in four different ways, via a bulk download, an API call or a webadress. comtrade can retrieve data from all of those, but validates the request first. In addition it can downlaod data from the Monthly Bulletin of Statistics (MBS) of Analytical Trade Tables and World Tables of International Trade Statistics Yearbook (ITSY) including footnotes.

For more information see the git hub repository or the help file.

Install from within Stata: net install comtrade, from("")

mmat2tex (on SSC)

mmat2tex exports a Mata matrix into LaTeX table format and saves it. Only the body of the table (i.e. rows and columns) is created, but further LaTeX commands at the beginning and end of the table can be included. The mata matrix can be string, real or complex.

Installation in Stata type "ssc mmat2tex" or download the package here.

A new version is available from within Stata: net install mmat2tex, from(


html2stata loads html tables into Stata. Tables are identified by <table>...</table>. It is possible to add links to the content of a cell, use the first row as variable names and process several tables per html webpage.

For more information see the git hub repository or the help file.

Install from within Stata: net install htmltab2stata, from("")


Obtaining and displaying information about running Stata instances under Microsoft Windows. stataid can close Stata instances using a Windows process id.

For more information see the git hub repository or the help file.

Install from within Stata: net install stataid, from("")


splag creates spatial lags using weights from a dataset. Can be installed in Stata by typing: net install splag , from(

The latest versions of all commands can be retrieved from within Stata by typing net from in the command window.