rm(list=ls()) setwd("C:/Users/harari/Desktop/Dropbox/enseignement/M2 EPOG econometrics/replication") library(tidyverse) #Compustat ------ compustat_original <- read_delim("compustat-1.csv",";", col_names = T, locale = locale(decimal_mark = ",")) compustat<-compustat_original %>% #select(-X11) %>% mutate(invest_netpayout_ratio=capx/(prstkc+dv-sstk),name="compustat") head(compustat) ggplot(compustat)+ geom_line(aes(x=year,y=invest_netpayout_ratio),color="grey") # Z1 ------ Z1_original <- read_delim("Z1.csv", ";", col_names = FALSE, skip = 5) Z1_names <- read_delim("Z1.csv", ";", col_names = T) %>% slice(0) names(Z1_original)<-names(Z1_names) rm(Z1_names) Z1<-Z1_original %>% select(year=1,operating.surplus=9, consumption.of.capital=3, dividends.paid=18,equity.liability=67, fixed.capital.formation=29) %>% filter(year>1945) %>% mutate(invest_netpayout_ratio=fixed.capital.formation/ (dividends.paid-equity.liability),name="Z1") Z1<-Z1 %>% select(year,invest_netpayout_ratio,name) compustat<-compustat %>% select(year,invest_netpayout_ratio,name) merged_db<-bind_rows(compustat,Z1) tail(merged_db) ggplot(merged_db,aes(x=year,y=invest_netpayout_ratio))+ ggtitle("Investment as a ratio of net financial payouts for the US economy and US-listed firms, and offshoring intensity, 1946–2016")+ geom_line(aes(colour=factor(name)))+ coord_cartesian(xlim = c(1945, 2016),ylim=c(0, 10))+ scale_x_continuous(breaks = seq(1945, 2016, by = 10))+ theme(plot.title=element_text(hjust=0.5), legend.position="right", panel.background =element_rect(fill="white")) #+scale_y_continuous(sec.axis = sec_axis(~ . + 10)) for a secondary axis # Fig 2 ---------- compustat.2<-compustat %>% filter(year>1970) %>% rename(profit=pi,taxes=txt,depreciation=dp,interest=Xint) %>% mutate(net.payouts=prstkc+dv-sstk, US.listed.firms=net.payouts/(profit-taxes+interest+depreciation), decade=floor(year/10)*10, decade2=case_when(year>=1970&year<1980~1970, year>=1980&year<1990~1980, year>=1990&year<2000~1990, year>=2000&year<2010~2000, year>=2010&year<2020~2010)) %>% group_by(decade) %>% mutate(average=mean(US.listed.firms)) %>% ungroup() Z1.2<-Z1 %>% filter(year>1970) %>% mutate(net.payouts=dividends.paid-equity.liability, US.economy=net.payouts/ (operating.surplus+consumption.of.capital)) ggplot(data=Z1.2,aes(x=year,y=US.economy,colour="US economy"))+geom_line()+ geom_line(data=compustat.2,aes(x=year,y=US.listed.firms,colour="US listed firms"))+ geom_point(data=compustat.2,aes(x=year,y=average, colour="Decade average"))+ ylab(label="")+ scale_colour_manual(limits=c("US economy","US listed firms","Decade average"),values=c("red","blue","blue")) #fig 5 ------ fig5 <- read.csv("./fig5.csv", sep=";") head(fig5) install.packages("gridExtra") library(gridExtra) names(fig5)<-c("isic","Industry","ncne_offshoring_mean","ptir_mean","ptir_p50","ptir_p75") p1<-ggplot(data=fig5,aes(x=ptir_p50,y=ncne_offshoring_mean))+geom_point()+geom_smooth(method="lm") p2<-ggplot(data=fig5,aes(x=ptir_p75,y=ncne_offshoring_mean))+geom_point()+geom_smooth(method="lm") grid.arrange(p1,p2,ncol=2,nrow=1)