Rajarshi Bhadra
Rajarshi Bhadra

Reputation: 1944

Keeping a constant column in plm

In a panel data frame I need to keep a constant column of 1 s. However after converstion from data.frame to pdata.frame the column of 1s gets dropped automatically. Is there any way I can keep the column?

Upvotes: 0

Views: 898

Answers (1)

Roman Luštrik
Roman Luštrik

Reputation: 70653

Next to being dropped, there is also a message indicating that it's a constant.

> xy <- data.frame(a = runif(5), b = runif(5), c = 1)
> pdata.frame(xy, drop.index = FALSE)
series c is constant and has been removed
                                                      a                  b
0.0236744922585785-0.950130922021344 0.0236744922585785  0.950130922021344
0.0879391168709844-0.295759258326143 0.0879391168709844  0.295759258326143
0.501141534885392-0.737975958967581   0.501141534885392  0.737975958967581
0.715363236144185-0.425528935389593   0.715363236144185  0.425528935389593
0.982470828806981-0.0960431189741939  0.982470828806981 0.0960431189741939

This behavior is hard coded into the pdata.frame function.

 if (length(cst.serie) > 0) {
        if (length(cst.serie) == 1) {
            cat(paste("series ", cst.serie, " is constant and has been removed\n", 
                sep = ""))
        }
        else {
            cat(paste("series ", paste(cst.serie, collapse = ", x"), 
                " are constants and have been removed\n", sep = ""))
        }
    }

You can either e-mail the package maintainer or remove this bit yourself (by creating a second function). Assuming there are theoretical grounds for keeping/not keeping constants.

Upvotes: 1

Related Questions