A reproducible example dataframe looks like this:
dur_exp_0204_p <- structure(list(hhid02 = c(823130649017, 823130649018, 823130649018,
823131407002, 823131407002, 823131407003, 823131407003, 823131407004,
823131407004, 823131407006, 823131407011, 823131407013, 823131407014,
823131407016, 823131407019, 823131407021, 823131407022, 823131407023,
101010314104, 101010314105, 101010314107), xa02 = c(8231306,
8231306, 8231306, 8231314, 8231314, 8231314, 8231314, 8231314,
8231314, 8231314, 8231314, 8231314, 8231314, 8231314, 8231314,
8231314, 8231314, 8231314, 1010103, 1010103, 1010103), hoso02 = c(49017,
49018, 49018, 7002, 7002, 7003, 7003, 7004, 7004, 7006, 7011,
7013, 7014, 7016, 7019, 7021, 7022, 7023, 14104, 14105, 14107
), sewing_machine = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 600, NA, NA, NA), electric_cook = c(0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), washing_machine = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4800, 0
), gas_cook = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0), sewing_equipment = c(0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, NA, NA), sewing = c(0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 600, 0, 0, 0), gas_electric_cook = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
hhexp2rl = c(16516.794921875, 27327.203125, 27327.203125,
16299.033203125, 12289.447265625, 20556.68359375, 7917.5751953125,
11280.525390625, 16914.984375, 12510.65234375, 20837.478515625,
19662.66015625, 25326.283203125, 20004.232421875, 16786.75,
6487.1474609375, 22275.740234375, 13802.505859375, NA, NA,
NA), tinh = structure(c(61L, 61L, 61L, 61L, 61L, 61L, 61L,
61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 61L, 1L,
1L, 1L), levels = c("101", "103", "104", "105", "106", "107",
"109", "111", "113", "115", "117", "201", "203", "205", "207",
"209", "211", "213", "215", "217", "221", "225", "301", "303",
"305", "401", "403", "405", "407", "409", "411", "501", "503",
"505", "507", "509", "511", "601", "603", "605", "607", "701",
"705", "707", "709", "711", "713", "715", "717", "801", "803",
"805", "807", "809", "811", "813", "815", "817", "819", "821",
"823", "302", "606", "816"), class = "factor"), hhwt = c(251.076034545898,
251.076034545898, 251.076034545898, 206.05549621582, 206.05549621582,
206.05549621582, 206.05549621582, 206.05549621582, 206.05549621582,
206.05549621582, 206.05549621582, 206.05549621582, 206.05549621582,
206.05549621582, 206.05549621582, 206.05549621582, 206.05549621582,
206.05549621582, NA, NA, NA), sewing_share = c(0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.0434703673458298,
NA, NA, NA), washing_share = c(0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, NA, NA, NA), cooking_share = c(0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NA, NA,
NA), provtariff = c(0.0576083160593838, 0.0576083160593838,
0.0576083160593838, 0.0576083160593838, 0.0576083160593838,
0.0576083160593838, 0.0576083160593838, 0.0576083160593838,
0.0576083160593838, 0.0576083160593838, 0.0576083160593838,
0.0576083160593838, 0.0576083160593838, 0.0576083160593838,
0.0576083160593838, 0.0576083160593838, 0.0576083160593838,
0.0576083160593838, 0.0186688797945901, 0.0186688797945901,
0.0186688797945901), provtariff_k = c(0.0637788726608478,
0.0637788726608478, 0.0637788726608478, 0.0637788726608478,
0.0637788726608478, 0.0637788726608478, 0.0637788726608478,
0.0637788726608478, 0.0637788726608478, 0.0637788726608478,
0.0637788726608478, 0.0637788726608478, 0.0637788726608478,
0.0637788726608478, 0.0637788726608478, 0.0637788726608478,
0.0637788726608478, 0.0637788726608478, 0.0346708431462636,
0.0346708431462636, 0.0346708431462636), year = c(2002, 2002,
2002, 2002, 2002, 2002, 2002, 2002, 2002, 2002, 2002, 2002,
2002, 2002, 2002, 2002, 2002, 2002, 2004, 2004, 2004), class = "data.frame")
I am trying to run a TWFE regression with the following code:
y_dur <- c("log(sewing_share)", "log(washing_share)", "log(cooking_share)")
dur_exp_tce_0204 <- list()
for(i in y_dur){
formula <- as.formula(paste(i, " ~ provtariff | year + hhid02"))
model <- feols(formula,
data = dur_exp_0204_p,
vcov = ~tinh,
weights = ~hhwt)
dur_exp_tce_0204[[i]] <- model
}
However, the warning message I am getting is:
Error: in feols(formula, data = dur_exp_0204_p, vcov = ~tin...:
The only variable 'provtariff' is collinear with the fixed effects. In such circumstances, the estimation is void.
This is not the case as (1) the year has varied, and (2) each household (hhid02
) has a different provtariff
value depending on the year. I have tried running the code with just hhid02
and year
as the FE separately and they ran no problem, the issue only arises when I include both terms as FE. Is there a reason for this? Thank you.