Why I cannot run fixed effects in my r studio?

It's weird. I am sure that I run successfully before. But I cannot now.

> reg.fe <- felm(daily_kwh ~ post + post:treatment|customer_id, data = df)
Error in chol.default(mat[ok, ok]) : 'a' must have dims > 0

I didn't have the above error message before. What happened?

library(lfe) #fixed effect
# my data set:
df <- data.frame(
    stringsAsFactors = FALSE,
           treatment = c(1L,1L,1L,1L,1L,1L,1L,
                         1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
                         1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
                         1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L),
         customer_id = c(1L,1L,1L,1L,1L,1L,1L,
                         1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
                         1L,1L,1L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,
                         2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L,2L),
                post = c(0,0,0,0,0,0,0,0,0,
                         0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,
                         0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,
                         1,1),
           daily_kwh = c(49.969696969697,51,
                         49.2424242424242,24.3396226415094,34.75,48.1666666666667,
                         78.3103448275862,62.0606060606061,48.7142857142857,
                         37.3,52.03125,56.3870967741936,55.5806451612903,
                         51.1379310344828,44.1034482758621,31.8666666666667,
                         33.3333333333333,51.6896551724138,64.40625,54,
                         45.2758620689655,38.1818181818182,38.1785714285714,
                         53.0967741935484,65.1212121212121,70.2068965517241,
                         66.3225806451613,35.0666666666667,28.1428571428571,
                         27.5483870967742,34.84375,42.4666666666667,39.3103448275862,
                         35.875,50.9310344827586,55.9,70.78125,128.533333333333,
                         122.551724137931,84.9375,42.0333333333333,

felm() is not a base R function, from what package it comes from? Can you please turn this into a proper self-contained reproducible example?

What do you mean? Do you mean I should change another tag for this question?

No, I mean that you should make a proper example that is reproducible, as it is right now it is not, since you are not including library calls and the sample data is not integrated with the code.
Please read the guide again this time even more carefully and try to follow along, it is not that hard, you basically just have to provide these two things.

  • A minimal dataset, necessary to reproduce the issue
  • The minimal runnable code necessary to reproduce the issue, which can be run
    on the given dataset, and including the necessary information on the used packages.

Thank you for your remind. I've changed it. Please have a look.

I succeed it again. Now it doesn't have any problem. How can I close this post?

It's good you solved the problem.
You can post and mark a solution if you wish. Or simply we can all stop posting here and that will be the end. See you around :slight_smile:

1 Like