使用FIXEST的FEOL进行固定效果的固定效果
我想采用一个固定效果模型,其中包括国家和年份固定效果以及国家与年份之间的互动效果。我尝试了以下方法:
library(fixest)
feols(y ~ x | country*year, data)
feols(y ~ x | country + year + country:year, data)
feols(y ~ x | country + year + I(country*year), data)
但是全部产生了错误:
Error in feols(y ~ x | country*: Error in res[[2]] : subscript out of bounds This error was unforeseen by the author of the function feols. If you think your call to the function is legitimate, could you report?
我该如何正确处理?
以下是我实际数据的前60行:
structure(list(NAME_1.y = c("Alibori", "Atakora", "Atlantique",
"Borgou", "Collines", "Donga", "Kouffo", "Littoral", "Mono",
"Oueme", "Plateau", "Zou", "Central", "Chobe", "Francistown",
"Gaborone", "Ghanzi", "Jwaneng", "Kgalagadi", "Kgatleng", "Kweneng",
"Lobatse", "North-East", "Selibe Phikwe", "South-East", "Southern",
"Mosteiros", "Paúl", "Porto Novo", "Praia", "Ribeira Grande",
"Santa Catarina", "Santa Cruz", "Sao Domingos", "Sao Filipe",
"Sao Miguel", "Sao Vicente", "Tarrafal", "Ashanti", "Brong Ahafo",
"Central", "Eastern", "Greater Accra", "Northern", "Upper East",
"Upper West", "Volta", "Western", "Bomet", "Bungoma", "Garissa",
"Isiolo", "Kajiado", "Kakamega", "Kericho", "Kiambu", "Kilifi",
"Kirinyaga", "Kisumu", "Kitui"), country = c("Benin", "Benin",
"Benin", "Benin", "Benin", "Benin", "Benin", "Benin", "Benin",
"Benin", "Benin", "Benin", "Botswana", "Botswana", "Botswana",
"Botswana", "Botswana", "Botswana", "Botswana", "Botswana", "Botswana",
"Botswana", "Botswana", "Botswana", "Botswana", "Botswana", "Cape Verde",
"Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde",
"Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde",
"Cape Verde", "Ghana", "Ghana", "Ghana", "Ghana", "Ghana", "Ghana",
"Ghana", "Ghana", "Ghana", "Ghana", "Kenya", "Kenya", "Kenya",
"Kenya", "Kenya", "Kenya", "Kenya", "Kenya", "Kenya", "Kenya",
"Kenya", "Kenya"), year = c(2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005),
yearvalue = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29874625.2288818,
0, 0, 0, 0, 0, 3119730.26764258, 0), sngq = c(40.3350714285714,
41.8501465773809, 32.1462559523809, 53.3881378348214, 51.3143125,
45.3290479910714, 30.9222321428571, 31.8178055555556, 29.6696517857143,
32.6099506302521, 30.4012254464286, 31.2331401098901, 48.3522208850932,
46.2751339285714, 51.8882346938775, 49.0520504201681, 49.9850803571429,
49.7569285714286, 48.6707276785714, 55.5698392857143, 49.1367147108843,
49.6709583333333, 47.7482008928571, 47.4158928571429, 47.1282232142857,
47.5937851190476, 45.5919585253456, 39.4586860119048, 34.0096227106227,
37.4234026227679, 35.2635037202381, 36.663, 39.3566339285714,
39.9424339285714, 38.4452915543576, 41.0157392857143, 46.5320122818358,
45.8783482142857, 45.1649102484472, 55.3813660714286, 40.4874038461538,
43.992073015873, 39.0866451990632, 54.0252091836735, 48.2392232142857,
45.3506232142857, 43.0489608516484, 36.9757994047619, 38.9841964285714,
36.4050892857143, 38.1211875, 46.1263392857143, 38.1707857142857,
30.9757380952381, 34.6969267857143, 46.7413571428571, 31.9214107142857,
41.9071845238095, 29.2133482142857, 41.2855535714286)), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -60L), groups = structure(list(
year = c(2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005, 2005,
2005, 2005), country = c("Benin", "Benin", "Benin", "Benin",
"Benin", "Benin", "Benin", "Benin", "Benin", "Benin", "Benin",
"Benin", "Botswana", "Botswana", "Botswana", "Botswana",
"Botswana", "Botswana", "Botswana", "Botswana", "Botswana",
"Botswana", "Botswana", "Botswana", "Botswana", "Botswana",
"Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde",
"Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde", "Cape Verde",
"Cape Verde", "Cape Verde", "Ghana", "Ghana", "Ghana", "Ghana",
"Ghana", "Ghana", "Ghana", "Ghana", "Ghana", "Ghana", "Kenya",
"Kenya", "Kenya", "Kenya", "Kenya", "Kenya", "Kenya", "Kenya",
"Kenya", "Kenya", "Kenya", "Kenya"), NAME_1.y = c("Alibori",
"Atakora", "Atlantique", "Borgou", "Collines", "Donga", "Kouffo",
"Littoral", "Mono", "Oueme", "Plateau", "Zou", "Central",
"Chobe", "Francistown", "Gaborone", "Ghanzi", "Jwaneng",
"Kgalagadi", "Kgatleng", "Kweneng", "Lobatse", "North-East",
"Selibe Phikwe", "South-East", "Southern", "Mosteiros", "Paúl",
"Porto Novo", "Praia", "Ribeira Grande", "Santa Catarina",
"Santa Cruz", "Sao Domingos", "Sao Filipe", "Sao Miguel",
"Sao Vicente", "Tarrafal", "Ashanti", "Brong Ahafo", "Central",
"Eastern", "Greater Accra", "Northern", "Upper East", "Upper West",
"Volta", "Western", "Bomet", "Bungoma", "Garissa", "Isiolo",
"Kajiado", "Kakamega", "Kericho", "Kiambu", "Kilifi", "Kirinyaga",
"Kisumu", "Kitui"), .rows = structure(list(1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L,
17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 27L,
28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L,
39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L,
50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -60L), .drop = TRUE))
我的回归没有国家和年份固定效果之间的相互作用
feols(sngq ~ yearvalue | country + year, df)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该查看所需的特定语法,如文档在这里 。也许您希望这样:
由
You should have a look at the specific syntax you want as described in the documentation here. Maybe you want it like this:
Created on 2022-07-01 by the reprex package (v2.0.1)