Load the package
library(tidyverse)
Load the data
aff_eu <- rio::import("../Data_output/ESTaff_eu.dta")
#aff_highEU <- rio::import("../Data_output/ESTaff_highEU.dta")
#aff_oecd <- rio::import("../Data_output/ESTaff_oecd.dta")
#aff <- rio::import("../Data_output/ESTaff.dta")
Preparation
# Sector
aff_eu$Sector <- "Agriculture & Mining"
aff_eu$Sector[aff_eu$FASectorClassNameAlph=="HeadQuarter"] <- "Services"
aff_eu$Sector[aff_eu$FASectorClassNameAlph=="Retail"] <- "Services"
aff_eu$Sector[aff_eu$FASectorClassNameAlph=="Service,Others"] <- "Services"
aff_eu$Sector[aff_eu$FASectorClassNameAlph=="Wholesale"] <- "Services"
aff_eu$Sector[aff_eu$FASectorClassNameAlph=="Manufacturing"] <- "Manufacturing"
# make country name
aff_eu$countryname <- countrycode::countrycode(
aff_eu$country,
origin = 'iso3c',
destination = "country.name"
)
# Rename
aff_eu$exitit <- ifelse(aff_eu$exit==1, "Exit", "Survive")
aff_eu2 <- aff_eu[, c("exitit", "GBR", "highEU", "Sector", "Aff_size", "N_Aff_EU", "countryname", "year", "Ratio")]
aff_eu2$GBR[aff_eu2$GBR==1] <- "UK"
aff_eu2$GBR[aff_eu2$GBR==0] <- "Other EU"
aff_eu2$highEU[aff_eu2$highEU==1] <- "High-income EU"
aff_eu2$highEU[aff_eu2$highEU==0] <- "Other EU"
# Rename
aff_eu2 <- aff_eu2 %>%
select(`High-income EU` = highEU,
`Number of affiliates in EU` = N_Aff_EU,
`Country name` = countryname,
`Affiliate size` = Aff_size,
`Exit dummy` = exitit,
`Japanese ownership ratio` = Ratio,
`Sector` = Sector,
`Year` = year,
`UK` = GBR
)
Country list
# N of obserbation by country and highEU
agg <- aff_eu2 %>%
group_by(`Country name`, `High-income EU`) %>%
summarise(N = n())
# Make subsample by High-income EU
agg_highEU <- filter(agg, `High-income EU` == "High-income EU")
agg_otherEU <- filter(agg, `High-income EU` == "Other EU")
# Rename
agg_highEU$`High-income EU` <- NULL
agg_otherEU$`High-income EU` <- NULL
# Rename `Country name` with `High-income EU`
names(agg_highEU)[names(agg_highEU)=="Country name"] <- "High-income EU"
names(agg_otherEU)[names(agg_otherEU)=="Country name"] <- "Other EU"
names(agg_highEU)[names(agg_highEU)=="N"] <- "N1"
names(agg_otherEU)[names(agg_otherEU)=="N"] <- "N2"
# Add two observations to agg_otherEU
dat2 <- data.frame(matrix(nrow = 2, ncol = 2))
names(dat2) <- names(agg_otherEU)
agg_otherEU <- rbind(agg_otherEU, dat2)
# Replace NA with blank
# Combine the data
agg2 <- cbind(agg_highEU, agg_otherEU)
tinytable
library(tinytable)
cap <- "Country list.\\label{tab:country-list}"
not <- "Note: This table shows the number of affiliates by the host country. The sample includes the Japanese affiliates in the EU."
c1 <- tt(agg2,
caption = cap,
notes = not,
width = 1) |>
group_tt(
j = list("High-income EU" = 1:2, "Other EU" = 3:4))
colnames(c1) <- c("Country", "N of affiliates","Country", "N of affiliates")
# Replace NA with blank
c1 <- format_tt(c1, replace = "")
c1
High-income EU |
Other EU |
Country list.\label{tab:country-list}
Country |
N of affiliates |
Country |
N of affiliates |
Note: This table shows the number of affiliates by the host country. The sample includes the Japanese affiliates in the EU. |
Austria |
162 |
Bulgaria |
27 |
Belgium |
855 |
Czechia |
450 |
Denmark |
144 |
Greece |
54 |
Finland |
99 |
Hungary |
288 |
France |
1782 |
Poland |
315 |
Germany |
3960 |
Portugal |
126 |
Ireland |
189 |
Romania |
81 |
Italy |
846 |
Slovakia |
90 |
Luxembourg |
90 |
Slovenia |
27 |
Netherlands |
2394 |
Spain |
648 |
Sweden |
261 |
|
|
United Kingdom |
4464 |
|
|
# Save as LaTex file
c1 |>
save_tt("../Tables/Table_countrylist.tex", overwrite = TRUE)
For LaTex, add the following code to the preamble:
\usepackage{tabularray}
\usepackage{float}
\usepackage{graphicx}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{siunitx}
\newcommand{\tinytableTabularrayUnderline}[1]{\underline{#1}}
\newcommand{\tinytableTabularrayStrikeout}[1]{\sout{#1}}
\NewTableCommand{\tinytableDefineColor}[3]{\definecolor{#1}{#2}{#3}}
Descriptive statistics
of the data
# Remove "countryname"
aff_eu2$`Country name` <- NULL
caption <- 'Descriptive statistics. \\label{tab:desc}'
longnote <- 'This table shows the descriptive statistics of the estimation sample. The sample includes the Japanese affiliates in the EU. The variable `Exit` is a dummy variable that takes 1 if the affiliate exits the host country. The variable `High-income EU` is a dummy variable that takes 1 if the affiliate is located in the high-income EU countries. The variable `Sector` is the sector of the affiliate. The variable `Affiliate size` is the size of the affiliate. The variable `Number of affiliates in EU` is the number of affiliates in the EU. The variable `Country name` is the name of the country where the affiliate is located.'
library(modelsummary)
t2 <- datasummary_balance(~UK,
data = aff_eu2,
title = caption,
#output = "latex",
)
t2
Descriptive statistics.
|
Other EU (N=12888)
|
UK (N=4464)
|
|
|
Mean
|
Std. Dev.
|
Mean
|
Std. Dev.
|
Number of affiliates in EU
|
|
5.7
|
7.6
|
5.8
|
8.3
|
Affiliate size
|
|
167.5
|
624.9
|
179.5
|
695.7
|
Japanese ownership ratio
|
|
0.7
|
0.4
|
0.7
|
0.4
|
Year
|
|
2016.3
|
3.5
|
2016.3
|
3.5
|
|
|
N
|
Pct.
|
N
|
Pct.
|
High-income EU
|
High-income EU
|
10782
|
83.7
|
4464
|
100.0
|
|
Other EU
|
2106
|
16.3
|
0
|
0.0
|
Exit dummy
|
Exit
|
3602
|
27.9
|
1272
|
28.5
|
|
Survive
|
9286
|
72.1
|
3192
|
71.5
|
Sector
|
Agriculture & Mining
|
108
|
0.8
|
99
|
2.2
|
|
Manufacturing
|
3465
|
26.9
|
981
|
22.0
|
|
Services
|
9315
|
72.3
|
3384
|
75.8
|
t2 <- datasummary_balance(~UK,
data = aff_eu2,
title = caption,
output = "latex",
)
t2
# Save as Latex file
library(kableExtra)
t2 |>
kableExtra::footnote(general = longnote, threeparttable = TRUE) %>%
kableExtra::save_kable("../Tables/Table_descriptive.tex")
Country list: simpler
method
library(modelsummary)
t1 <- datasummary_crosstab(`Country name` ~ `High-income EU`,
statistic = ~ N ,
title = 'Country list \\label{tab:countrylist}',
data = aff_eu2)
t1
t1 <- datasummary_crosstab(`Country name` ~ `High-income EU`,
statistic = ~ N ,
title = 'Country list \\label{tab:countrylist}',
output = "latex",
data = aff_eu2)
t1
# Save as Latex file
library(kableExtra)
t1 |>
#kableExtra::footnote(general = longnote, threeparttable = TRUE) %>%
kableExtra::save_kable("../Tables/Table_countrylist.tex")