-1

I tried to run a panel var on dataset I got from Statistics Sweden and here is what I get:

df<- read_excel("Inkfördelning per kommun.xlsx")
nujavlar <- pvarfeols(dependent_vars = c("Kvintil-1", "Kvintil-4", "Kvintil-5"),
lags = 1,
transformation = "demean",
data = df,
panel_identifier = c("Kommun", "Year")
)
Error: Can't subset columns that don't exist.
x Column `Kvintil-1` doesn't exist.

I often get this message too:

Warning in xtfrm.data.frame(x) : cannot xtfrm data frames
Error: Can't subset columns that don't exist.
x Location 2 doesn't exist.
ℹ There are only 1 column.

I have made sure that all data is numeric. I have also tried cleaning my workspace and restarted the programme. I also tried to convert it into a paneldata frame with palm package. I also tried converting my entity variable "Kommun" (Municipality) into factors and it still doesn't work. Here's the data if someone wants to give it a go.

https://docs.google.com/spreadsheets/d/16Ak_Z2n6my-5wEw69G29_NLryQKcrYZC/edit?usp=sharing&ouid=113164216369677216623&rtpof=true&sd=true

Pathum Bandara
  • 343
  • 2
  • 3
  • 12

1 Answers1

0

The column names in your dataframe are Kvintil 1, not Kvintil-1, so the variable you are referring to really does not exist. Please be aware that in R, variable names cannot have hyphens and it is good practice to avoid spaces in variable names because it is annoying to refer to variables with spaces. I have included a reproducible example below.

library(tidyverse)
library(gsheet)
library(panelvar)
url <- 'docs.google.com/spreadsheets/d/16Ak_Z2n6my-5wEw69G29_NLryQKcrYZC'
df <- gsheet2tbl(url) %>%
  rename(Kvintil1 = `Kvintil 1`) %>%
  rename(Kvintil2 = `Kvintil 2`) %>%
  rename(Kvintil3 = `Kvintil 3`) %>%
  rename(Kvintil4 = `Kvintil 4`) %>%
  rename(Kvintil5 = `Kvintil 5`) %>%
  as.data.frame()
 
nujavlar <- pvarfeols(                      
  dependent_vars = c("Kvintil1", "Kvintil4", "Kvintil5"),
  lags = 1,
  transformation = "demean",
  data = df,
  panel_identifier = c("Kommun", "Year"))
jrcalabrese
  • 2,184
  • 3
  • 10
  • 30