1

I am trying to do a panel regression with the plm-function (Package ‘plm’) in R. But apparently there's something wrong with my data structure. This is my model:

fixedeff <- plm(iwyg~edyear*secondos,
                data = cohort_long_gesamt_panel,
                model = "within", 
                index = c("idpers","year"))

I get this error message:

Fehler: Can't convert <labelled<double>> to <double>.
Backtrace:
  1. plm::plm(...)
  2. plm:::plm.fit(...)
  4. plm:::pmodel.response.data.frame(...)
  5. plm:::ptransform(y, model = model, effect = effect, theta = theta)
  7. plm:::Within.pseries(x, effect)
     ...
 18. vctrs::vec_default_cast(...)
 19. vctrs::stop_incompatible_cast(...)
 20. vctrs::stop_incompatible_type(...)
 21. vctrs:::stop_incompatible(...)
 22. vctrs:::stop_vctrs(...)

That's the beginning of the structure-output:

Classes ‘pdata.frame’ and 'data.frame': 332 obs. of  18 variables:
 $ idpers     : Factor w/ 190 levels "102010003","105410003",..: 1 1 1 2 3 3 4 5 5 5 ...
  ..- attr(*, "names")= chr [1:332] "102010003-14" "102010003-15" "102010003-19" "105410003-18" ...
  ..- attr(*, "index")=Classes ‘pindex’ and 'data.frame':   332 obs. of  2 variables:
  .. ..$ idpers: Factor w/ 190 levels "102010003","105410003",..: 1 1 1 2 3 3 4 5 5 5 ...
  .. ..$ year  : Factor w/ 5 levels "14","15","17",..: 1 2 5 4 2 5 5 1 2 4 ...
 $ secondos   : dbl+lbl [1:332] 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,...
   ..@ label       : chr "respondent's secondos status"
   ..@ format.stata: chr "%8.0g"
   ..@ labels      : Named num  1 2 3 999
   .. ..- attr(*, "names")= chr [1:4] "secondos" "foreign origin" "no foreign origin" "not documented"
   ..@ index       :Classes ‘pindex’ and 'data.frame':  332 obs. of  2 variables:
   .. ..$ idpers: Factor w/ 190 levels "102010003","105410003",..: 1 1 1 2 3 3 4 5 5 5 ...
   .. ..$ year  : Factor w/ 5 levels "14","15","17",..: 1 2 5 4 2 5 5 1 2 4 ...
 $ swiss      : dbl+lbl [1:332] 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...
   ..@ label       : chr "swiss citizenship"
   ..@ format.stata: chr "%8.0g"
   ..@ labels      : Named num  0 1
   .. ..- attr(*, "names")= chr [1:2] "no" "yes"
   ..@ index       :Classes ‘pindex’ and 'data.frame':  332 obs. of  2 variables:
   .. ..$ idpers: Factor w/ 190 levels "102010003","105410003",..: 1 1 1 2 3 3 4 5 5 5 ...
   .. ..$ year  : Factor w/ 5 levels "14","15","17",..: 1 2 5 4 2 5 5 1 2 4 ...

Maybe someone can help me?

Helix123
  • 3,502
  • 2
  • 16
  • 36
Ezgi
  • 11
  • 1
  • 1
    You may have imported your data from SPSS using `haven`. Seems like `plm` can't cope with having column types "labelled". So convert them to normal R vectors using `cohort_long_gesamt_panel <- haven::zap_labels(cohort_long_gesamt_panel)`. – dash2 Apr 26 '21 at 15:07
  • Thank you soso much!! I was stuck for weeks. I really appreciate it. – Ezgi Apr 27 '21 at 08:51
  • Can you make a reproducible example (see https://stackoverflow.com/a/5963610/4640346), e.g., by using `dput` on a (subset) of your data? Also, showing the code to produce the data would help. – Helix123 Apr 27 '21 at 10:35
  • Could be, this is fixed in the latest version on CRAN. Without a reproducible example, we will not find out. – Helix123 May 03 '21 at 21:28

0 Answers0