# Source the script and capture the returned data frame
df_exc1 <- df
exc_name <- '/exc2_vf_men'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1_men <- df
exc_name <- '/exc2_vf_women'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1_women <- df
# Define columns to keep
columns_to_keep <- c(2, 4, 3, 7, 8, 9)
# Select specific columns from each table
df_exc1 <- df_exc1[, c(1, columns_to_keep)]  # Include the first column for event times
df_exc1_men <- df_exc1_men[, columns_to_keep]
df_exc1_women <- df_exc1_women[, columns_to_keep]
# Merge tables horizontally
merged_table <- cbind(df_exc1, df_exc1_men, df_exc1_women)
columns_to_order<-c(1,2,2+6,2+12,3,3+6,3+12,4,4+6,4+12,5,5+6,5+12,6,6+6,6+12,7,7+6,7+12)
merged_table <- merged_table[, columns_to_order]
merged_table[19,1] <- '$\\theta^{pre}$'
merged_table[21,1] <- '$\\theta^{post}$'
# Create custom LaTeX headers
header1 <- paste0(
" \\multirow{2}{*}{$\\theta_{es}(e)$} & \\multicolumn{3}{c|}{ Children Medicaid Elig.} &" ,
"\\multicolumn{3}{c|}{Children on Medicaid}  & " ,
"\\multicolumn{3}{c|}{Medicaid Elig.}  & " ,
"\\multicolumn{3}{c|}{Medicaid}  & " ,
"\\multicolumn{3}{c|}{Private}  & " ,
"\\multicolumn{3}{c|}{Any}  \\\\ ")
header2 <- paste0(
" & All & Men & Women & All & Men & Women & All & Men & Women & All & Men & Women & ",
"All & Men & Women & All & Men & Women \\\\")
header3 <- paste0(
" & 1.a & 1.b & 1.c & 2.a & 2.b & 2.c & ",
"3.a & 3.b & 3.c & 4.a & 4.b & 4.c & ",
"5.a & 5.b & 5.c & 6.a & 6.b & 6.c \\\\"
)
# Generate LaTeX table body with a line before "Pre-Average"
body <- apply(merged_table, 1, function(row) {
if (row[1] == "$\\theta^{pre}$") {  # Check if the first column (Event Time) is "Pre-Average"
return(paste("\\hline", paste(row, collapse = " & ")))  # Add a line before this row
} else {
return(paste(row, collapse = " & "))
}
})
body <- paste(body, collapse = " \\\\\n")
final_rows <- paste0(
"\\hline\n",
"Gender & All & Men & Women & All & Men & Women & All & Men & Women & All & Men & Women & ",
"All & Men & Women & All & Men & Women \\\\\n",
"N & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & ",
"588 & 588 & 588 & 588 & 588 & 588 \\\\\n"
)
#Combine headers, table body, and final rows
latex_code <- paste0(
"\\begin{tabular}{|c|ccc|ccc|ccc|ccc|ccc|ccc|}\n\\hline\n",
header1, "\n",header2, "\n", header3, " \\\\\n\\hline\n",
body, " \\\\\n\\hline\n",
final_rows, "\\hline\n\\end{tabular}"
)
# Combine headers and table body (from tabular only)
#latex_code <- paste0(
#  "\\begin{tabular}{|c|ccc|ccc|ccc|ccc|ccc|ccc|}\n\\hline\n",
#  header1, "\n", header2, "\n\\hline\n",
#  body, " \\\\\n\\hline\n\\end{tabular}"
#)
# Save LaTeX code to a file
write(latex_code, file = paste0(output_path,output_name))
#Store Environment
to_keep2 <- ls()
#name of exercise (Will load coefficients)
#output name (Will save table under this name)
exc_name <- '/exc1_vf'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1 <- df
exc_name <- '/exc2_vf_men'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1_men <- df
exc_name <- '/exc2_vf_women'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1_women <- df
# Define columns to keep
columns_to_keep <- c(2, 4, 3, 7, 8, 9)
# Select specific columns from each table
df_exc1 <- df_exc1[, c(1, columns_to_keep)]  # Include the first column for event times
df_exc1_men <- df_exc1_men[, columns_to_keep]
df_exc1_women <- df_exc1_women[, columns_to_keep]
# Merge tables horizontally
merged_table <- cbind(df_exc1, df_exc1_men, df_exc1_women)
columns_to_order<-c(1,2,2+6,2+12,3,3+6,3+12,4,4+6,4+12,5,5+6,5+12,6,6+6,6+12,7,7+6,7+12)
merged_table <- merged_table[, columns_to_order]
merged_table[19,1] <- '$\\theta^{pre}$'
merged_table[21,1] <- '$\\theta^{post}$'
# Create custom LaTeX headers
header1 <- paste0(
" \\multirow{3}{*}{$\\theta_{es}(e)$} & \\multicolumn{3}{c|}{ Children Medicaid Elig.} &" ,
"\\multicolumn{3}{c|}{Children on Medicaid}  & " ,
"\\multicolumn{3}{c|}{Medicaid Elig.}  & " ,
"\\multicolumn{3}{c|}{Medicaid}  & " ,
"\\multicolumn{3}{c|}{Private}  & " ,
"\\multicolumn{3}{c|}{Any}  \\\\ ")
header2 <- paste0(
" & All & Men & Women & All & Men & Women & All & Men & Women & All & Men & Women & ",
"All & Men & Women & All & Men & Women \\\\")
header3 <- paste0(
" & 1.a & 1.b & 1.c & 2.a & 2.b & 2.c & ",
"3.a & 3.b & 3.c & 4.a & 4.b & 4.c & ",
"5.a & 5.b & 5.c & 6.a & 6.b & 6.c \\\\"
)
# Generate LaTeX table body with a line before "Pre-Average"
body <- apply(merged_table, 1, function(row) {
if (row[1] == "$\\theta^{pre}$") {  # Check if the first column (Event Time) is "Pre-Average"
return(paste("\\hline", paste(row, collapse = " & ")))  # Add a line before this row
} else {
return(paste(row, collapse = " & "))
}
})
body <- paste(body, collapse = " \\\\\n")
final_rows <- paste0(
"\\hline\n",
"N & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & ",
"588 & 588 & 588 & 588 & 588 & 588 \\\\\n"
)
#Combine headers, table body, and final rows
latex_code <- paste0(
"\\begin{tabular}{|c|ccc|ccc|ccc|ccc|ccc|ccc|}\n\\hline\n",
header1, "\n",header2, "\n", header3, " \\\\\n\\hline\n",
body, " \\\\\n\\hline\n",
final_rows, "\\hline\n\\end{tabular}"
)
# Combine headers and table body (from tabular only)
#latex_code <- paste0(
#  "\\begin{tabular}{|c|ccc|ccc|ccc|ccc|ccc|ccc|}\n\\hline\n",
#  header1, "\n", header2, "\n\\hline\n",
#  body, " \\\\\n\\hline\n\\end{tabular}"
#)
# Save LaTeX code to a file
write(latex_code, file = paste0(output_path,output_name))
#Combine headers, table body, and final rows
latex_code <- paste0(
"\\begin{tabular}{|c|ccc|ccc|ccc|ccc|ccc|ccc|}\n\\hline\n",
header1, "\n",header2, "\n", header3, "\n\\hline\n",
body, " \\\\\n\\hline\n",
final_rows, "\\hline\n\\end{tabular}"
)
# Combine headers and table body (from tabular only)
#latex_code <- paste0(
#  "\\begin{tabular}{|c|ccc|ccc|ccc|ccc|ccc|ccc|}\n\\hline\n",
#  header1, "\n", header2, "\n\\hline\n",
#  body, " \\\\\n\\hline\n\\end{tabular}"
#)
# Save LaTeX code to a file
write(latex_code, file = paste0(output_path,output_name))
#Store Environment
to_keep2 <- ls()
#name of exercise (Will load coefficients)
#output name (Will save table under this name)
exc_name <- '/exc1_vf'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1 <- df
exc_name <- '/exc2_vf_men'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1_men <- df
exc_name <- '/exc2_vf_women'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1_women <- df
# Define columns to keep
columns_to_keep <- c(2, 4, 3, 7, 8, 9)
# Select specific columns from each table
df_exc1 <- df_exc1[, c(1, columns_to_keep)]  # Include the first column for event times
df_exc1_men <- df_exc1_men[, columns_to_keep]
df_exc1_women <- df_exc1_women[, columns_to_keep]
# Merge tables horizontally
merged_table <- cbind(df_exc1, df_exc1_men, df_exc1_women)
columns_to_order<-c(1,2,2+6,2+12,3,3+6,3+12,4,4+6,4+12,5,5+6,5+12,6,6+6,6+12,7,7+6,7+12)
merged_table <- merged_table[, columns_to_order]
merged_table[19,1] <- '$\\theta^{pre}$'
merged_table[21,1] <- '$\\theta^{post}$'
# Create custom LaTeX headers
header1 <- paste0(
" \\multirow{3}{*}{$\\theta_{es}(e)$} & \\multicolumn{3}{c|}{ Children Medicaid Elig.} &" ,
"\\multicolumn{3}{c|}{Children on Medicaid}  & " ,
"\\multicolumn{3}{c|}{Medicaid Elig.}  & " ,
"\\multicolumn{3}{c|}{Medicaid}  & " ,
"\\multicolumn{3}{c|}{Private}  & " ,
"\\multicolumn{3}{c|}{Any}  \\\\ ")
header2 <- paste0(
" & All & Men & Women & All & Men & Women & All & Men & Women & All & Men & Women & ",
"All & Men & Women & All & Men & Women \\\\")
header3 <- paste0(
" & 1.a & 1.b & 1.c & 2.a & 2.b & 2.c & ",
"3.a & 3.b & 3.c & 4.a & 4.b & 4.c & ",
"5.a & 5.b & 5.c & 6.a & 6.b & 6.c \\\\"
)
# Generate LaTeX table body with a line before "Pre-Average"
body <- apply(merged_table, 1, function(row) {
if (row[1] == "$\\theta^{pre}$") {  # Check if the first column (Event Time) is "Pre-Average"
return(paste("\\hline", paste(row, collapse = " & ")))  # Add a line before this row
} else {
return(paste(row, collapse = " & "))
}
})
body <- paste(body, collapse = " \\\\\n")
final_rows <- paste0(
"\\hline\n",
"N & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & ",
"588 & 588 & 588 & 588 & 588 & 588 \\\\\n"
)
#Combine headers, table body, and final rows
latex_code <- paste0(
"\\begin{tabular}{|c|ccc|ccc|ccc|ccc|ccc|ccc|}\n\\hline\n",
header1, "\n",header2, "\n", header3, "\n\\hline\n" "\\hline\n",
#Store Environment
to_keep2 <- ls()
#name of exercise (Will load coefficients)
#output name (Will save table under this name)
exc_name <- '/exc1_vf'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1 <- df
exc_name <- '/exc2_vf_men'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1_men <- df
exc_name <- '/exc2_vf_women'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1_women <- df
# Define columns to keep
columns_to_keep <- c(2, 4, 3, 7, 8, 9)
# Select specific columns from each table
df_exc1 <- df_exc1[, c(1, columns_to_keep)]  # Include the first column for event times
df_exc1_men <- df_exc1_men[, columns_to_keep]
df_exc1_women <- df_exc1_women[, columns_to_keep]
# Merge tables horizontally
merged_table <- cbind(df_exc1, df_exc1_men, df_exc1_women)
columns_to_order<-c(1,2,2+6,2+12,3,3+6,3+12,4,4+6,4+12,5,5+6,5+12,6,6+6,6+12,7,7+6,7+12)
merged_table <- merged_table[, columns_to_order]
merged_table[19,1] <- '$\\theta^{pre}$'
merged_table[21,1] <- '$\\theta^{post}$'
# Create custom LaTeX headers
header1 <- paste0(
" \\multirow{3}{*}{$\\theta_{es}(e)$} & \\multicolumn{3}{c|}{ Children Medicaid Elig.} &" ,
"\\multicolumn{3}{c|}{Children on Medicaid}  & " ,
"\\multicolumn{3}{c|}{Medicaid Elig.}  & " ,
"\\multicolumn{3}{c|}{Medicaid}  & " ,
"\\multicolumn{3}{c|}{Private}  & " ,
"\\multicolumn{3}{c|}{Any}  \\\\ ")
header2 <- paste0(
" & All & Men & Women & All & Men & Women & All & Men & Women & All & Men & Women & ",
"All & Men & Women & All & Men & Women \\\\")
header3 <- paste0(
" & 1.a & 1.b & 1.c & 2.a & 2.b & 2.c & ",
"3.a & 3.b & 3.c & 4.a & 4.b & 4.c & ",
"5.a & 5.b & 5.c & 6.a & 6.b & 6.c \\\\"
)
# Generate LaTeX table body with a line before "Pre-Average"
body <- apply(merged_table, 1, function(row) {
if (row[1] == "$\\theta^{pre}$") {  # Check if the first column (Event Time) is "Pre-Average"
return(paste("\\hline", paste(row, collapse = " & ")))  # Add a line before this row
} else {
return(paste(row, collapse = " & "))
}
})
body <- paste(body, collapse = " \\\\\n")
final_rows <- paste0(
"\\hline\n",
"N & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & ",
"588 & 588 & 588 & 588 & 588 & 588 \\\\\n"
)
#Combine headers, table body, and final rows
latex_code <- paste0(
"\\begin{tabular}{|c|ccc|ccc|ccc|ccc|ccc|ccc|}\n\\hline\n",
header1, "\n",header2, "\n", header3, "\n\\hline\n", "\\hline\n",
body, " \\\\\n\\hline\n",
final_rows, "\\hline\n\\end{tabular}"
)
# Save LaTeX code to a file
write(latex_code, file = paste0(output_path,output_name))
#Store Environment
to_keep2 <- ls()
#name of exercise (Will load coefficients)
#output name (Will save table under this name)
exc_name <- '/exc1_vf'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1 <- df
exc_name <- '/exc2_vf_men'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1_men <- df
exc_name <- '/exc2_vf_women'
source("table_importer.R")
# Source the script and capture the returned data frame
df_exc1_women <- df
# Define columns to keep
columns_to_keep <- c(2, 4, 3, 7, 8, 9)
# Select specific columns from each table
df_exc1 <- df_exc1[, c(1, columns_to_keep)]  # Include the first column for event times
df_exc1_men <- df_exc1_men[, columns_to_keep]
df_exc1_women <- df_exc1_women[, columns_to_keep]
# Merge tables horizontally
merged_table <- cbind(df_exc1, df_exc1_men, df_exc1_women)
columns_to_order<-c(1,2,2+6,2+12,3,3+6,3+12,4,4+6,4+12,5,5+6,5+12,6,6+6,6+12,7,7+6,7+12)
merged_table <- merged_table[, columns_to_order]
merged_table[19,1] <- '$\\theta^{pre}$'
merged_table[21,1] <- '$\\theta^{post}$'
# Create custom LaTeX headers
header1 <- paste0(
" \\multirow{3}{*}{$\\theta_{es}(e)$} & \\multicolumn{3}{c|}{ Children Medicaid Elig.} &" ,
"\\multicolumn{3}{c|}{Children on Medicaid}  & " ,
"\\multicolumn{3}{c|}{Medicaid Elig.}  & " ,
"\\multicolumn{3}{c|}{Medicaid}  & " ,
"\\multicolumn{3}{c|}{Private}  & " ,
"\\multicolumn{3}{c|}{Any}  \\\\ ")
header2 <- paste0(
" & All & Men & Women & All & Men & Women & All & Men & Women & All & Men & Women & ",
"All & Men & Women & All & Men & Women \\\\")
header3 <- paste0(
" & 1.a & 1.b & 1.c & 2.a & 2.b & 2.c & ",
"3.a & 3.b & 3.c & 4.a & 4.b & 4.c & ",
"5.a & 5.b & 5.c & 6.a & 6.b & 6.c \\\\"
)
# Generate LaTeX table body with a line before "Pre-Average"
body <- apply(merged_table, 1, function(row) {
if (row[1] == "$\\theta^{pre}$") {  # Check if the first column (Event Time) is "Pre-Average"
return(paste("\\hline", paste(row, collapse = " & ")))  # Add a line before this row
} else {
return(paste(row, collapse = " & "))
}
})
body <- paste(body, collapse = " \\\\\n")
final_rows <- paste0(
"\\hline\n",
"N & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & 588 & ",
"588 & 588 & 588 & 588 & 588 & 588 \\\\\n"
)
#Combine headers, table body, and final rows
latex_code <- paste0(
"\\begin{tabular}{|c|ccc|ccc|ccc|ccc|ccc|ccc|}\n\\hline\n",
header1, "\n",header2, "\n", header3, "\n\\hline", "\\hline",
body, " \\\\\\hline\n",
final_rows, "\\hline\\end{tabular}"
)
# Save LaTeX code to a file
write(latex_code, file = paste0(output_path,output_name))
rm(list = ls())
cat("\014")  # ctrl+L
# Load necessary libraries
library(readxl)
library(xtable)
library(dplyr)
# Add relevant path:
# main_path: where Excel files are stored
# output_path: where .tex tables will be saved
main_path <- "/Users/bulla/Dropbox/Research Agenda/Medicaid_Expansion_spill_over/Drafts/Data/CPS/Final/Event Study/New_cs/Tables" #Insert path here
output_path <- "/Users/bulla/Dropbox/Research Agenda/Medicaid_Expansion_spill_over/Drafts/Data/CPS/Final/outputs/tables" #Insert path here
setwd(output_path)
output_name <- '/tab1_new.tex'
source("table_1.R")
output_name <- '/tab3_new.tex'
source("table_3.R")
output_name <- '/tab4_new.tex'
source("table_4.R")
output_name <- '/tab5_new.tex'
source("table_5.R")
output_name <- '/tab6_new.tex'
source("table_6.R")
rm(list = ls())
cat("\014")  # ctrl+L
# Load necessary libraries
library(readxl)
library(xtable)
library(dplyr)
# Add relevant path:
# main_path: where Excel files are stored
# output_path: where .tex tables will be saved
main_path <- "/Users/bulla/Dropbox/Research Agenda/Medicaid_Expansion_spill_over/Drafts/Data/CPS/Final/Event Study/New_cs/Tables" #Insert path here
output_path <- "/Users/bulla/Dropbox/Research Agenda/Medicaid_Expansion_spill_over/Drafts/Data/CPS/Final/outputs/tables" #Insert path here
setwd(output_path)
output_name <- '/tab1_new.tex'
source("table_1.R")
output_name <- '/tab3_new.tex'
source("table_3.R")
output_name <- '/tab4_new.tex'
source("table_4.R")
output_name <- '/tab5_new.tex'
source("table_5.R")
rm(list = ls())
cat("\014")  # ctrl+L
# Load necessary libraries
library(readxl)
library(xtable)
library(dplyr)
# Add relevant path:
# main_path: where Excel files are stored
# output_path: where .tex tables will be saved
main_path <- "/Users/bulla/Dropbox/Research Agenda/Medicaid_Expansion_spill_over/Drafts/Data/CPS/Final/Event Study/New_cs/Tables" #Insert path here
output_path <- "/Users/bulla/Dropbox/Research Agenda/Medicaid_Expansion_spill_over/Drafts/Data/CPS/Final/outputs/tables" #Insert path here
setwd(output_path)
output_name <- '/tab1_new.tex'
source("table_1.R")
output_name <- '/tab3_new.tex'
source("table_3.R")
output_name <- '/tab4_new.tex'
source("table_4.R")
output_name <- '/tab5_new.tex'
source("table_5.R")
output_name <- '/tab6_new.tex'
source("table_6.R")
#This R scrip import tables from excel and export them in.tex
# Clear console
rm(list = ls())
cat("\014")  # ctrl+L
# Load necessary libraries
library(readxl)
library(xtable)
library(dplyr)
# Add relevant path:
# main_path: where Excel files are stored
# output_path: where .tex tables will be saved
main_path <- "/Users/bulla/Dropbox/Research Agenda/Medicaid_Expansion_spill_over/Drafts/Data/CPS/Final/Event Study/New_cs/Tables" #Insert path here
output_path <- "/Users/bulla/Dropbox/Research Agenda/Medicaid_Expansion_spill_over/Drafts/Data/CPS/Final/outputs/tables" #Insert path here
setwd(output_path)
output_name <- '/tab1_new.tex'
source("table_1.R")
output_name <- '/tab3_new.tex'
source("table_3.R")
output_name <- '/tab4_new.tex'
source("table_4.R")
output_name <- '/tab5_new.tex'
source("table_5.R")
output_name <- '/tab6_new.tex'
source("table_6.R")
#This R scrip import tables from excel and export them in.tex
# Clear console
rm(list = ls())
cat("\014")  # ctrl+L
# Load necessary libraries
library(readxl)
library(xtable)
library(dplyr)
# Add relevant path:
# main_path: where Excel files are stored
# output_path: where .tex tables will be saved
main_path <- "/Users/bulla/Dropbox/Research Agenda/Medicaid_Expansion_spill_over/Drafts/Data/CPS/Final/Event Study/New_cs/Tables" #Insert path here
output_path <- "/Users/bulla/Dropbox/Research Agenda/Medicaid_Expansion_spill_over/Drafts/Data/CPS/Final/outputs/tables" #Insert path here
setwd(output_path)
output_name <- '/tab1_new.tex'
source("table_1.R")
output_name <- '/tab3_new.tex'
source("table_3.R")
output_name <- '/tab4_new.tex'
source("table_4.R")
output_name <- '/tab5_new.tex'
source("table_5.R")
output_name <- '/tab6_new.tex'
source("table_6.R")
# Clear console
rm(list = ls())
cat("\014")  # ctrl+L
start.time <- Sys.time()
############################   Part 1: Start   ###################################
############################                 ###################################
################################################################################
# Set directory
# main_path -> Include path for the Replication Package folder
main_path <- " your path  " #Insert path here
data_path <-    paste0(main_path,"/dtafiles")
raw_data_path <-    paste0(main_path,"/rawdata")
code_path <-    paste0(main_path,"/acodes")
code_path_p1 <- paste0(code_path,"/Part1")
code_path_p2 <- paste0(code_path,"/Part2")
code_path_p3 <- paste0(code_path,"/Part3")
# Conditional EPS export: eps=1 export figures in eps as well.
eps<-1
setwd(main_path)
# Clear console
rm(list = ls())
cat("\014")  # ctrl+L
start.time <- Sys.time()
############################   Part 1: Start   ###################################
############################                 ###################################
################################################################################
# Set directory
# main_path -> Include path for the Replication Package folder
main_path <- "/Users/bulla/Dropbox/Borella_Genetics/HRS Data Work/For_submission/3 Replication Package clean" #Insert path here
data_path <-    paste0(main_path,"/dtafiles")
raw_data_path <-    paste0(main_path,"/rawdata")
code_path <-    paste0(main_path,"/acodes")
code_path_p1 <- paste0(code_path,"/Part1")
code_path_p2 <- paste0(code_path,"/Part2")
code_path_p3 <- paste0(code_path,"/Part3")
# Conditional EPS export: eps=1 export figures in eps as well.
eps<-1
setwd(main_path)
# If this is the first time runing the code, set intall_lib==1 and get all needed packages.
# If already installed, set intall_lib==0
# Install relevant libraries
intall_lib<-1
if (intall_lib==1) {
setwd(code_path_p1)
source("Install_Libraries.R")
setwd(main_path)
}
