setwd("Downloads/Replication/")
ttt <- readRDS("data/deal_details.RDS")
ttt[DealNumber == 2461418020,]
ttt <- setDT(readRDS("data/deal_details.RDS"))
librar(data.table)
ttt <- setDT(readRDS("data/deal_details.RDS"))
library(data.table)
ttt <- setDT(readRDS("data/deal_details.RDS"))
ttt[DealNumber == 2461418020,]
ttt <- ttt[DealNumber != 2461418020]
ttt <- readRDS("data/deal_details.RDS")
ttt[ttt$DealNumber != 2461418020]
ttt <- ttt[ttt$DealNumber != 2461418020]
saveRDS(ttt, "data/deal_details.RDS")
fread("identifiers/identifiers.csv")
ids <- fread("identifiers/identifiers.csv")
merge(ids, unique(ttt[,.(DealNumber, gvkeyT)]), on = "DealNumber")
merge(ids, unique(ttt[,.(DealNumber, gvkeyT)]), by = "DealNumber")
ids
merge(ids, unique(ttt[,.(DealNumber, gvkeyT)]), by.y = "DealNumber", by.x = "V1")
merge(ids, unique(ttt[,list(DealNumber = as.integer(DealNumber), gvkeyT)]), by.y = "DealNumber", by.x = "V1")
ttt[,list(DealNumber = as.character(DealNumber), gvkeyT)]
unique(ttt[,list(DealNumber = as.character(DealNumber), gvkeyT)])
ids <- unique(ttt[DealNumber != 2461418020, list(DealNumber = as.character(DealNumber), gvkeyT)])
ids <- fread("identifiers/identifiers.csv")
ttt[, uniqueN(DealNumber)]
id_new <- unique(ttt[DealNumber != 2461418020, list(DealNumber = as.character(DealNumber), gvkeyT)])
ids <- ids[V1 != 2461418020]
ids <- ids[V1 != 2461418020, "DealNumber" := as.character(DealNumber)]
ids <- ids[V1 != 2461418020, "DealNumber" := as.character(V1)]
id_new[, source = "handcollection"]
id_new[, source := "handcollection"]
merge(ids, id_new, on = "DealNumber")
merge(ids, id_new, on = "DealNumber", all.x = T)
ids <- merge(ids, id_new, on = "DealNumber", all.x = T)
ids[is.na(source), source := "GM2014"]
fwrite(ids, "identifiers/identifiers.csv")
rm(list = ls()); gc()
# Define the log file name
log_file <- "logfiles/data_cleaning_preparation.txt"
# Open a connection to the log file
sink(log_file, append = TRUE)
cat("Starting script at: ", Sys.time(), "\n")
print("Step 1: Handcollected deal and bid information")
print("(A) Clean and add control variables")
source("Code/Step1/clean_deal_details_to_GM_format.R")
print("Step 2: PPA data from Dealstats")
print("(A) Clean data")
source("Code/Step2/clean_dealstat_data.R")
print("(B) Generate Dealstats - SDC Merge Table")
source("Code/Step2/SDC_DealStats_linktable_create.R")
print("(C) Generate Descriptive Statistics on PPA for all-cash deals")
source("Code/Step2/goodwill_descriptives.R")
print("(D) Add purchase price allocation data to deal and bid information")
source("Code/Step2/add_ppa.R")
print("Step 3: Accounting Treatment of Goodwill")
print("(1) Descriptive Statistics on impairment incidence and magnitude")
source("Code/Step3/impairment_descriptives.R")
print("Simulate expected discounted impact of goodwill impairments on future earnings by industry based on descriptive statistics")
source("Code/Step3/industry_earnings_impact_counterfac.R")
print("Step 4: Set up estimation data set to be exported to Julia")
source("code/Step4/prepare_estimation_data_industry_variation.R")
print("Step 5: Tables 3 and 4")
print("(A) Table 3: Descriptive Statistics on sample auctions")
source("Code/Step5/auction_descriptives.R")
print("(B) Table 4: Bidder type determinants model")
source("Code/Step5/type_determinants_model.R")
cat("Script completed at: ", Sys.time(), "\n")
sink()
sink(type = "message")
rm(list = ls()); gc()
# Define the log file name
log_file <- "logfiles/data_cleaning_preparation.txt"
# Open a connection to the log file
sink(log_file, append = TRUE)
cat("Starting script at: ", Sys.time(), "\n")
print("Step 1: Handcollected deal and bid information")
print("(A) Clean and add control variables")
source("Code/Step1/clean_deal_details_to_GM_format.R")
print("Step 2: PPA data from Dealstats")
print("(A) Clean data")
source("Code/Step2/clean_dealstat_data.R")
print("(B) Generate Dealstats - SDC Merge Table")
source("Code/Step2/SDC_DealStats_linktable_create.R")
print("(C) Generate Descriptive Statistics on PPA for all-cash deals")
source("Code/Step2/goodwill_descriptives.R")
print("(D) Add purchase price allocation data to deal and bid information")
source("Code/Step2/add_ppa.R")
print("Step 3: Accounting Treatment of Goodwill")
print("(1) Descriptive Statistics on impairment incidence and magnitude")
source("Code/Step3/impairment_descriptives.R")
print("Simulate expected discounted impact of goodwill impairments on future earnings by industry based on descriptive statistics")
source("Code/Step3/industry_earnings_impact_counterfac.R")
print("Step 4: Set up estimation data set to be exported to Julia")
source("code/Step4/prepare_estimation_data_industry_variation.R")
print("Step 5: Tables 3 and 4")
print("(A) Table 3: Descriptive Statistics on sample auctions")
source("Code/Step5/auction_descriptives.R")
print("(B) Table 4: Bidder type determinants model")
source("Code/Step5/type_determinants_model.R")
cat("Script completed at: ", Sys.time(), "\n")
sink()
sink(type = "message")
library(data.table)
library(dplyr)
library(xtable)
library(ggplot2)
source("code/utilities/aux_functions.R")
sdcds_mt <- fread("data/ppa/sdc_dealstats_mergetable.csv")
ds_dt <- readRDS("data/ppa/20221110_dealstats_cleaned.RDS")
select_dt <- sdcds_mt[, .(transaction_id, DealNumber, cash_only, SICT)]
setkey(select_dt, transaction_id)
setkey(ds_dt, transaction_id)
select_dt<- merge(ds_dt, select_dt)
var_names <- c("transaction_id","DealNumber", "cash_only", "sale_date", "SICT", names(select_dt)[grepl("_ppa|price", names(select_dt))])
select_dt <- select_dt[,(var_names), with = F]
select_dt[, year_ma := year(sale_date)]
# Note purchase price scale was wrongly recorded for ID 30224-2 and 31375-2
select_dt[transaction_id %in% c("30224-2", "31375-2"), mvic_price := mvic_price * 1000]
remove_policy <- select_dt[DealNumber %in% select_dt[select_dt[, duplicated(DealNumber)], DealNumber], .(DealNumber, transaction_id)]
remove_policy[, deal_id := as.numeric(substr(transaction_id, 1, nchar(transaction_id)-2))]
remove_policy[, deal_info_rank := rank(deal_id), by = DealNumber]
select_dt <- select_dt[!(transaction_id %in% remove_policy[deal_info_rank==1, transaction_id])]
# Add FF-12-Industries
industry_def <- readRDS("Data/FF12_siccode_match.RDS")
select_dt[, sict := as.integer(SICT)]
# for overlap merge create a second sic code variable
select_dt[, sict2 := sict]
setkey(select_dt, sict, sict2)
setkey(industry_def, sich_lower, sich_upper)
# merge
test <- foverlaps(industry_def[ID!= 12], select_dt,nomatch = NULL)
select_dt <- rbind(test, select_dt[!(DealNumber %in% test$DealNumber)], fill = T)
rm(test)
select_dt[is.na(ID), ID := 12]
select_dt[ID == 12, c("Desc_short", "Desc_long", "desc") := list("Other",
"Other -- Mines, Constr, BldMt, Trans, Hotels, Bus Serv, Entertainment",
"Other")]
# Calculate Goodwill Allocation percentage
select_dt[, goodwill_alloc := goodwill_ppa/mvic_price]
ct <- data.table(split_var = c("All", unique(select_dt$desc)), "Target Industry" = c("All", unique(select_dt$desc)))
desc_by_group(select_dt, "goodwill_alloc", split_var = "desc", classification_table = ct,
path = paste0("output/ppa_descriptives.tex"))
# output ppa averages by industry for counterfactuals
rbind(data.table(desc = "All", V1 = select_dt[, mean(goodwill_alloc, na.rm = T)]), select_dt[, mean(goodwill_alloc, na.rm = T), by = desc])
saveRDS(rbind(data.table(desc = "All", V1 = select_dt[, mean(goodwill_alloc, na.rm = T)]), select_dt[, mean(goodwill_alloc, na.rm = T), by = desc]),
paste0("data/cleaned_data/goodwill_ppa_statistics.RDS"))
desc_by_group(select_dt, "goodwill_alloc", split_var = "desc", classification_table = ct,
path = "output/ppa_descriptives.tex")
desc_by_group(select_dt, "goodwill_alloc", split_var = "desc", classification_table = ct,
path = "output/ppa_descriptives.tex")
rm(list = ls()); gc()
# Define the log file name
log_file <- "logfiles/data_cleaning_preparation.txt"
# Open a connection to the log file
sink(log_file, append = TRUE)
cat("Starting script at: ", Sys.time(), "\n")
print("Step 1: Handcollected deal and bid information")
print("(A) Clean and add control variables")
source("Code/Step1/clean_deal_details_to_GM_format.R")
print("Step 2: PPA data from Dealstats")
print("(A) Clean data")
source("Code/Step2/clean_dealstat_data.R")
print("(B) Generate Dealstats - SDC Merge Table")
source("Code/Step2/SDC_DealStats_linktable_create.R")
print("(C) Generate Descriptive Statistics on PPA for all-cash deals")
source("Code/Step2/goodwill_descriptives.R")
print("(D) Add purchase price allocation data to deal and bid information")
source("Code/Step2/add_ppa.R")
print("Step 3: Accounting Treatment of Goodwill")
print("(1) Descriptive Statistics on impairment incidence and magnitude")
source("Code/Step3/impairment_descriptives.R")
print("Simulate expected discounted impact of goodwill impairments on future earnings by industry based on descriptive statistics")
source("Code/Step3/industry_earnings_impact_counterfac.R")
print("Step 4: Set up estimation data set to be exported to Julia")
source("code/Step4/prepare_estimation_data_industry_variation.R")
print("Step 5: Tables 3 and 4")
print("(A) Table 3: Descriptive Statistics on sample auctions")
source("Code/Step5/auction_descriptives.R")
print("(B) Table 4: Bidder type determinants model")
source("Code/Step5/type_determinants_model.R")
cat("Script completed at: ", Sys.time(), "\n")
sink()
sink(type = "message")
