- Julia 44.9%
- Stata 42.6%
- R 12.5%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| analysis | ||
| data_prep | ||
| README.md | ||
Replication Code for "Causal Evidence of Task-Switching Cost in Organ Transplantation"
This repository contains the replication code for:
Liu, J., Jin, Y., & Adler, J. T. (2026). Causal Evidence of Task-Switching Cost in Organ Transplantation. Nature Human Behaviour.
Data
This study used data from the Scientific Registry of Transplant Recipients (SRTR). The SRTR data system includes data on all donors, wait-listed candidates, and transplant recipients in the United States, submitted by the members of the Organ Procurement and Transplantation Network (OPTN). Due to federal data use agreements, the raw data cannot be made publicly available. Data access can be requested through the SRTR website: https://www.srtr.org/requesting-srtr-data/data-requests/. Access is subject to a data use agreement and may require institutional review board approval or exemption.
Requirements
- Stata 18 with packages:
reghdfe,ivreghdfe,psmatch2,estout - Julia v1.11.3 with packages:
Printf,Pkg,HDF5,DataFrames,Dates,DelimitedFiles,CSV,JLD2,FileIO,BrowseTables,Tables,JDF,Plots,DataStructures,Arrow,LinearAlgebra,Statistics,StatsBase,Suppressor,Random,Distributions,HypothesisTests - R 4.5.2 with packages:
tidyverse,patchwork,randtests,lubridate,foreign,stargazer,dplyr,nlme,MASS,caret,ggplot2,gridExtra,ggthemes,gsubfn,stringr,psych,Hmisc,corrplot,DescTools,scales,tidyr,stats,fitdistrplus,plotrix,plm,lfe,lawstat,furrr,specr
File Structure
data_prep/
├── prep1.do # Data and variable preparation
└── prep2.jl # Imputation, classification
analysis/
├── main.do # Main results (Tables 1, S1-S13; Figures 1-4, S1, S3-S4)
├── center_scheduling.jl # Center scheduling analysis (Discussion section)
├── runs_test/
│ ├── runstest_prep.jl # Runs tests for randomization checks
│ └── plot_runstest.R # P-value histograms (Figure S2)
└── spec_curve/
├── prep_spec_file.jl # YAML config file
├── spec_curve_reg.do # 2048 specification regressions
└── spec_curve_plot_table.R # Specification curve (Figure S5, Table S10)
Usage
Run the scripts in the following order:
Step 1: Data Preparation
# 1a. Stata: Build master dataset
# Creates: surgery_master.dta, analysis_master.dta
stata -b do data_prep/prep1.do
# 1b. Julia: Imputation and classification
# Inputs: surgery_master.csv (export from surgery_master.dta)
# Creates: dt1_prep.csv, ctrdf.csv, surgdf.csv
julia data_prep/prep2.jl
Data flow:
prep1.do → surgery_master.dta + analysis_master.dta
↓ (export to CSV)
prep2.jl → dt1_prep.csv + ctrdf.csv + surgdf.csv
Step 2: Main Analysis (Stata)
# Main regression results
# Inputs: analysis_master.dta
# Creates: Tables 1, S1-S13; Figures 1-4, S1, S3-S4
stata -b do analysis/main.do
Step 3: Center Scheduling Analysis (Julia)
# Center scheduling patterns for Discussion section
# Inputs: dt1_prep.csv, ctrdf.csv, surgdf.csv
# Output: Console statistics (dedicated vs flexible centers)
julia analysis/center_scheduling.jl
Step 4: Runs Test for Randomization (Julia → R)
# 4a. Julia: Calculate runs test p-values
# Inputs: dt1_prep.csv, surgdf.csv
# Creates: runs_test_df.csv
julia analysis/runs_test/runstest_prep.jl
# 4b. R: Plot p-value histograms
# Inputs: runs_test_df.csv
# Creates: Figure S2
Rscript analysis/runs_test/plot_runstest.R
Step 5: Specification Curve Analysis (Julia → Stata → R)
# 5a. Julia: Generate specification file
# Creates: spec_curve_run.txt
julia analysis/spec_curve/prep_spec_file.jl
# 5b. Stata: Run 2048 specifications
# Inputs: dt1_prep.csv, spec_curve_run.yml (split into p1/p2)
# Creates: specurvep1.csv, specurvep2.csv
stata -b do analysis/spec_curve/spec_curve_reg.do
# 5c. R: Plot specification curve and generate table
# Inputs: specurvep1.csv, specurvep2.csv
# Creates: Figure S5, Table S10
Rscript analysis/spec_curve/spec_curve_plot_table.R
Output Mapping
| Paper | Output File | Description |
|---|---|---|
| Table 1 | table1_summary.tex |
Summary statistics |
| Figure 1 | figure1_survival.pdf |
Kaplan-Meier survival curves |
| Figure 2 | figure2_similarity.pdf |
Heterogeneity by organ similarity |
| Figure 3 | figure3_timelag.pdf |
Heterogeneity by time lag |
| Figure 4 | figure4_intraday.pdf |
Heterogeneity by intraday sequence |
| Table S1 | tableS1_main_moderator.tex |
Main results with moderators |
| Table S2 | tableS2_dow.tex |
Day-of-week and daytime controls |
| Table S3 | tableS3_reset.tex |
7-day vs 14-day reset threshold |
| Table S5 | tableS5_multi.tex |
Multi-specialty subsamples |
| Table S6 | tableS6_balance.tex |
PSM covariate balance |
| Table S7 | tableS7_psm.tex |
PSM results (5 matching methods) |
| Table S8 | tableS8_iv_first.tex |
IV first stage |
| Table S9 | tableS9_iv_2sls.tex |
IV 2SLS results |
| Table S10 | tableS10_speccurve_coef.tex |
Specification curve coefficients |
| Table S11 | tableS11_altmodels.tex |
Probit and Cox models |
| Table S12 | tableS12_outcomes.tex |
Alternative outcomes |
| Table S13 | tableS13_subgroups.tex |
Organ subgroup analysis |
| Figure S1 | figureS1_direction.pdf |
Primary vs secondary switch |
| Figure S2 | figureS2_runstest.pdf |
Runs test p-value histograms |
| Figure S3 | figureS3_psm_density.pdf |
PSM density plots |
| Figure S4 | figureS4_association.pdf |
Covariate balance after PSM |
| Figure S5 | figureS5_speccurve.pdf |
Specification curve |
Note: Tables S4 and S14 are static illustrative tables not generated by code.