# Stata-Code

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

**xtdcce2 and xtcd2**

**xtcse2**

**xtbreak**

**xthst**

**simulate2 / psimulate2**

**multishell**

**xtbalance2**

**comtrade**

**mmat2tex**

**htmltab2stata**

**stataid**

**splag**

Downloads from SSC

**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(https://janditzen.github.io/xtdcce2/)*

**xtcse2 **

**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(https://janditzen.github.io/xtdcce2/)*

**xtbreak** (joint work with Yiannis Karavias and Joakim Westerlund)

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

Slides from the 2020 Swiss User Group meeting are available here.

For the latest version see **Github**.

**multishell**

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 install multishell, from(http://www.ditzen.net/Stata) *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("https://janditzen.github.io/xthst/") 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("https://janditzen.github.io/simulate2/") 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 https://github.com/JanDitzen/xtbalance2 or *ssc install xtbalance2*

**comtrade**

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("https://janditzen.github.io/comtrade/")

**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(http://www.ditzen.net/Stata)*

**html2stata**

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("https://janditzen.github.io/htmltab2stata/")

**stataid**

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("https://janditzen.github.io/stataid/")

**splag**

**splag **creates spatial lags using weights from a dataset. Can be installed in Stata by typing:* net install splag , from(http://www.ditzen.net/Stata)*

The latest versions of all commands can be retrieved from within Stata by typing *net from http://www.ditzen.net/Stata *in the command window.