Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 具有时间固定效应的PPML包装重力_R_Non Linear Regression - Fatal编程技术网

R 具有时间固定效应的PPML包装重力

R 具有时间固定效应的PPML包装重力,r,non-linear-regression,R,Non Linear Regression,我试图在R中的PPML回归中加入时间固定效应(使用model.matrix生成多年的假人) 如果没有时间固定效应,则回归为: require(gravity) my_model <- PPML(y="v", dist="dist", x=c("land","contig","comlang_ethno", "smctry","tech","exrate"), vce_robust=T, data=database)

我试图在R中的PPML回归中加入时间固定效应(使用model.matrix生成多年的假人)

如果没有时间固定效应,则回归为:

require(gravity)
my_model <- PPML(y="v", dist="dist", 
            x=c("land","contig","comlang_ethno",
            "smctry","tech","exrate"), 
            vce_robust=T, data=database)
require(重力)

my_model只需确保
年份
是一个因素,然后您就可以使用简单的
glm
-函数作为

glm(y~dist+年份,family=“quasipoisson”)

这将为您提供带有
年份
的模拟结果/固定效果。然后使用以下公式计算鲁棒SE:

lmtest::coeftest(EstimationResults.PPML,vcov=sandwich::vcovHC(model.PPML,“HC1”))


PPML
函数没有其他功能,只是不够灵活。

我会对前面的答案发表评论,但没有足够的声誉。PPML命令中的重力模型指定v=dist×exp(land+contig+comlang\u ethno+smctry+tech+exrate+TimeFE)=exp(log(dist)+land+contig+comlang\u ethno+smctry+tech+exrate+TimeFE)

glm
中的公式应将指数中的变量作为其RHS,因为它表示链接函数(泊松默认值为自然对数)产生的线性预测值。总之,你的命令应该是

glm(v ~ log(dist) + land + contig + comlang_ethno + smctry + tech + exrate + factor(year), 
      family='quasipoisson')

特别是,您需要在RHS上记录距离(与前面的答案不同)。

除了
PPML
glm
之外,您还可以使用函数
femlm
(来自包
FENmlm
)解决问题,该函数处理最大似然模型的固定效应估计

功能
femlm
的两个主要优点是:

  • 您可以根据需要添加任意多个固定效果,并单独处理它们,从而导致计算时间,而无需与glm进行比较(特别是当固定效果包含许多类别时)

  • 标准错误可以通过直观的命令聚集在一起

下面是一个关于您的问题的示例(只有两个变量和年份固定效应):

该代码估计变量
log(dist)
land
的系数,具有
year
固定效应;然后显示系数表,其中包含两个变量的聚集标准误差(w.r.t.

除了你最初的问题,现在假设你有一个更复杂的情况,有三个固定的影响:
country\u i
country\u j
。你会写:

res = femlm(v ~ log(dist) + land | country_i + country_j + year, base)
然后,您可以轻松地处理聚集的标准错误:

# Cluster w.r.t. country_i (default is first cluster encountered):
summary(res, se = "cluster") 
summary(res, se = "cluster", cluster = "year") # cluster w.r.t. year cluster
# Two-way clustering:
summary(res, se = "twoway") # two-way clustering w.r.t. country_i & country_j
# two way clustering w.r.t. country_i & year:
summary(res, se = "twoway", cluster = c("country_i", "year")) 
有关该软件包的更多信息,请访问

# Cluster w.r.t. country_i (default is first cluster encountered):
summary(res, se = "cluster") 
summary(res, se = "cluster", cluster = "year") # cluster w.r.t. year cluster
# Two-way clustering:
summary(res, se = "twoway") # two-way clustering w.r.t. country_i & country_j
# two way clustering w.r.t. country_i & year:
summary(res, se = "twoway", cluster = c("country_i", "year"))