install.packages("gtools") install.packages("plm") library(gtools) library(plm) setwd("E:/post") matriz <- combinations(15,2, repeats.allowed = "FALSE") # This line of code is to obtain all the combination of two units in your panel (that is why the second number is "2"). The first number (15) is the number of units in your panel. If you have 100 units and you want to analyze the impact of the removal of 7 nations you should substitute 15 by 100 and 2 by 7, respectively. write.csv(matriz,"matriz.csv",row.names = FALSE) # Here we are saving the previous matrix so you can use it in eviews base <- read.csv("E:/post/indicators.csv") # this loads the panel data with investment and salary # panel_base <- pdata.frame(base, index = c("code", "year"), drop.index = FALSE) # model_base <- pmg(salary ~ inv, panel_base, model = "mg", index = NULL, trend = FALSE) panel_base_all <- pdata.frame(base, index = c("code", "year"), drop.index = TRUE) # Here we are putting the data as pdata.frame object so it can used by the plm R package model_base_all <- pmg(salary ~ inv, panel_base_all, model = "mg", index = NULL, trend = FALSE) # Here we obtaint the Mean Group estimation for the whole panel summary(model_base_all) coef_matriz <- matrix(,nrow = 15,ncol = 2) # we create a matrix to store the coefficient and their t-statistics for the case of only one unit removal for (i in 1:15){ panel_base <- subset(base, ! code %in% i) panel_base <- pdata.frame(panel_base, index = c("code", "year"), drop.index = TRUE) model_base <- pmg(salary ~ inv, panel_base, model = "mg", index = NULL, trend = FALSE) coef_matriz[i,1] <- summary(model_base)[11][[1]][2,1] # In the first column of the matrix coef_matrix we store the coefficient estimates coef_matriz[i,2] <- summary(model_base)[11][[1]][2,3] # In the second column of the matrix coef_matrix we store the t statistics estimates } coef_matriz_large <- matrix(,nrow = 105,ncol = 2) # All the combinations of the numbers from 1 to 15 taking 2 of them at once yield 105 combinations. That is why for the case of two units removal, the matrix has 105 rows. for (i in 1:105){ panel_base <- subset(base, ! code %in% matriz[i,]) panel_base <- pdata.frame(panel_base, index = c("code", "year"), drop.index = TRUE) model_base <- pmg(salary ~ inv, panel_base, model = "mg", index = NULL, trend = FALSE) coef_matriz_large[i,1] <- summary(model_base)[11][[1]][2,1] coef_matriz_large[i,2] <- summary(model_base)[11][[1]][2,3] } write.csv(coef_matriz,"coef_matriz.csv",row.names = FALSE) # here we save the matrix for the removal of one unit. Then you use this csv file to plot the coefficient estimates and their respective t-statistics. write.csv(coef_matriz_large,"coef_matriz_large.csv",row.names = FALSE) # here we save the matrix for the removal of two units. Then you use this csv file to plot the coefficient estimates and their respective t-statistics.