Addressing sample selection bias for machine learning methods (replication data)


Addressing sample selection bias for machine learning methods (replication data)

Dylan Brewer and Alyssa Carlson

Accepted at Journal of Applied Econometrics, 2023


This replication package contains files required to reproduce results, tables, and figures using Matlab and Stata. We divide the project into instructions to replicate the simulation, the result from Huang et al (2006), and the application.


For reproducing the simulation results

Included files in *\Simulation with short descriptions:

  • SSML_simfunc: function that produces individual simulations runs
  • SSML_simulation: script that loops over the SSML_simfunc for different DGP and multiple simulation runs
  • SSML_figures: script that generates all figures for the paper
  • SSML_compilefunc: function that compiles the results from SSML_simulation for the SSML_figures script

Steps for replicating simulation:

  1. Save SSML_simfunc, SSML_simulation, SSML_figures, SSML_compilefunc to the same folder. This location will be referred to as the FILEPATH.
  2. Create OUTPUT folder inside the FILEPATH location.
  3. Change the FILEPATH location inside SSML_simulation and SSML_figures.
  4. Run SSML_simulation to produce simulation data and results.
  5. Run SSML_figures to produce figures.

Huang et al replication

For reproducing the Huang et. al. (2006) replication results.

Included files in *\HuangetalReplication with short descriptions:

  • SSML_huangrep: script that replicates the results from Huang et. al. (2006)

Obtaining the dataset:

Go to and save file as ""

Steps for replicating results:

  1. Save SSML_huangrep and the breast cancer data to the same folder. This location will be referred to as the FILEPATH.
  2. Change the FILEPATH location inside SSML_huangrep
  3. Run SSML_huangrep to produce results and figures.


For reproducing the application section results.

Included program files in *\Application with short descriptions:

  • Stata wrapper code that will run all application replication files
  • Cleans election outcomes data
  • Cleans open elections data
  • Cleans demographics data
  • Cleans FIPS code data
  • Cleans Klarner gubernatorial data
  • Merges cleaned datasets together
  • Generates summary statistics tables and figures
  • Runs L1 penalized probit for the first stage
  • G9_prediction_202308.m: Trains learners and makes predictions
  • G10_figures_202308.m: Generates figures of prediction patterns
  • Generates final figures and tables of results
  • Examines the effect of requiring the control function is not dropped from LASSO
  • latexTable.m: Code by Eli Duenisch to write LaTeX tables from Matlab (

Included non-confidential data in subdirectory *\Application\Data\:

Confidential data suppressed in subdirectory *\Application\CD\:

These data cannot be transferred as part of the data use agreement with the CQ Press. Thus, the files are not included.

There is no batch download--downloads for each year must be done by hand. For each year, download as many state outcomes as possible and name the files YYYYa.csv, YYYYb.csv, etc. (Example: 1970a.csv, 1970b.csv, 1970c.csv, 1970d.csv). See line 18 of for file structure information.

Steps for replicating application:

  1. Download confidential data from the CQ Press.
  2. Change the working directory in on line 18 to the application folder.
  3. Change local matlabpath in on line 18 to the appropriate location.
  4. Set directory and file path in G9_prediction_202308.m and G10_figures_202308.m as necessary.
  5. Run in Stata to run all programs.
  6. All output (figures and tables) will be saved to subdirectory *\Application\Output.


Contact Dylan Brewer ( or Alyssa Carlson ( for help with replication.

Metadata Access
Creator Brewer, Dylan; Carlson, Alyssa
Publisher ZBW - Leibniz Informationszentrum Wirtschaft
Publication Year 2023
Rights Creative Commons Attribution 4.0 (CC-BY); Download
OpenAccess true
Contact ZBW - Leibniz Informationszentrum Wirtschaft
Language English
Resource Type Collection
Discipline Economics