I have a panel data:
Panel Data set - gravity model international trade
My R code:
#importing dataset
df <- read_excel("DataSet_Final.xlsx",
col_types = c("text", "numeric", "text",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "text", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric",
"numeric", "numeric", "numeric"))
glimpse(df)
# Transforming some variables into log, for better interpretation and normalization of the distribution
df$log_pop <- log(df$Population)
df$log_dist <- log(df$Distance)
df$log_GDP <- log(df$GDP)
df$log_Trade <- log(df$Trade)
# Dropping unnecessary variable
df$Helper <- NULL
head(df)
df %>%
group_by(Year, CountryName) %>%
mutate(group_id = cur_group_id())
panel_data <- pdata.frame(df, index = c("CountryName", "Counterpart_Country_Name", "Year"))
Error:
Warning message:
In pdata.frame(df, index = c("CountryName", "Counterpart_Country_Name", :
duplicate couples (id-time) in resulting pdata.frame
to find out which, use, e.g., table(index(your_pdataframe), useNA = "ifany")
dput(read.table("CountryName CountryCode Counterpart_Country_Name TradePartnerCode Year Export
Belgium 124 Austria 122 1997 1.82394E+14
Belgium 124 Austria 122 1998 2.01838E+14
Belgium 124 Austria 122 1999 1968240347.9
Belgium 124 Austria 122 2000 1931467793
Belgium 124 Austria 122 2001 2067659120
Belgium 124 Austria 122 2002 2260078352
Belgium 124 Austria 122 2003 2684795303", sep="\t", header=TRUE))
What I am trying to achieve is to be able to do a fixed effects regression however I have encountered errors which I provided above. How can I deal with this error? The thing is I cannot really drop observations as each country trades with another country for multiple years.
I have tried to find answers on StackOverflow with no solution that have helped me out with this problem.
dput(head(df)). Edit your question and include the output of thestructure(...).dputfunction.