5 min read

GMM模型理解

很老的笔记,总结一下。

供需求函数

{qtD=α0+α1pt+utqtS=β0+β1pt+vtqtD=qtS

这是供需求函数,我们肯定不能直接用qt=α0+α1pt+ut去跑回归。 因为我们首先不知道这是代表供给还是需求函数,实际上谁也不是。

{qt=α0+α1pt+utqt=β0+β1pt+vt

解得:

pt=β0α0β1α1+vtutβ1α1ptvt,ut

我们知道,当xμ线性相关,x就是内生了(陈强 2014)

这个时候我们需要引入 工具变量,假设是天气xt

工具变量的两个条件:

  • 在供给方程中,天气影响pt的,因此Cov(pt,xt)01
  • xtut,vt都不像相关,天气是外生的,除了自身,不受到其他变量决定。

重新写供给函数

{qtS=β0+β1pt+βxt+vtqtS=β0+β1ptρ>0βxt×vt

所以,

这里涉及到 2SLS

第一步,

pt=γ0+γ1xt+δtpt=pt^(xt)+δ^t

第二步,

{qt=α0+α1pt^+ut+α1(ptpt^)qt=β0+β1pt^+vt+β1(ptpt^)

{qt=α0+α1(γ^0+γ^1xt)+ut+α1(ptpt^)qt=β0+β1(γ^0+γ^1xt)+vt+β1(ptpt^)

然后就可以回归了。

矩估计

  • 一矩:E(x)=μ
  • 二矩:E(x2)=Var(x)+E2(x)=σ2+μ2

如果我们假设xN(μ,σ),有两个未知数,因此我们需要两个假设,μσ,并使用两个方程去估计,就是我们的矩。 通常我们用样本矩来猜测,

{1ni=1nxi=μ^1ni=1nxi2=μ^2+σ^2

因此任意的f(x)都可以叫做矩估计。

这里我们使用第二个假设,

E(ziϵi)=0E(zi(yixiβ))=0E(ziyi)=E(zixi)βE(zixi)1E(ziyi)=β

我们用样本估计,来估计总体估计!!!

E(zixi)1E(ziyi)=ββ^=(1ni=1nzixi)1(1ni=1nziyi)β^=(zixi)1(ziyi)

样本矩除了E(β),还有Var(β)要估计。

β^β=(zixi)1zi(xβ+ϵ)ββ^β=(zixi)1zixβ+(zixi)1ziϵββ^β=β+(zixi)1ziϵββ^β=(zixi)1ziϵβ^β=(1ni=1nzixi)1(1ni=1nziϵi)β^β=SZX1g¯

这里假设SZX1=(1ni=1nzixi)1g¯=(1ni=1nziϵi)

因此用样本估计估计总体估计时, 我们假设在大样本的情况下,

SZX1g¯E(SZX1g¯)=E(SZX1)E(g¯)=E(SZX1)0=0

注意这里E(SZX1)是一个数,所以可以分离。

所以E(β^β)=0E(β^)=β

Avar(β^)=E((β^β)2)=E((SZX1g¯)2)

这里有比较简单的推导方法。

第一个方程是 xzγ^=(zz)1zxx^=zγ^=z[(zz)1zx]=[z(zz)1z]x=px

同理 β^=(x^x^)1x^yβ^=(xPPx)1x^yβ^=(xPx)1x^yβ^=(xx^)1x^yβ^=(zx)1zy

full rank 就是矩估计的条件

能够作为工具变量的变量数量不能少于内生变量的数量。

弱工具变量检验

Shea’s partial R2

假设y=x1β1+x2β2+μ,其中只有x2是内生的,工具变量为z2。 做回归 x2x1e1z2x1e2。 其中e1e2分别衡量了x2z2除了x1以外的其他波动。 再做e1e2Rp2,如果Rp2大,说明不是弱工具变量。

过度识别检验

z的数量超过内生的x数量。 只有这样E(zϵ)=0,否则不满足 因此,我们假设有K个x,r个是内生的,z有 m个,因此回归,

ϵx1++xKr+z1+zm+error 如果得到的R2大,或者说nR2比较于Θ2(mr)而大的话,那么E(zϵ)=0的条件就不满足了。 因此要求R2尽可能低,即P值要小。

GMM

GMM是过度识别的时候使用,因为n(x)<n(z)。 这个时候1ni=1nzi(yixβ^)不能等于0了,无解,但是可以使其平方最小。

一步还是两步

一步是满足同方差假设的,所以还是用两步吧。

弱工具变量容易有偏

y=1+2x+μ

强工具变量

x=0.5z+0.2μ+0.1v

弱工具变量

x=0.01z+0.2μ+0.1v

library(tidyverse)
beta_cb1 <- 1:100
beta_cb2 <- 1:100
a <- data_frame(
  mu = rnorm(100),
  v  = rnorm(100),
  z  = rnorm(100)
)
## Warning: `data_frame()` is deprecated as of tibble 1.1.0.
## Please use `tibble()` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
for (i in 1:100){
  
b <- 
  as.data.frame(resample_bootstrap(a)) %>% 
  mutate(
    x1 = 0.5*z + 0.2*mu + 0.1*v,
    x2 = 0.01*z + 0.2*mu + 0.1*v,
    y1 = 1 + 2*x1 + mu,
    y2 = 1 + 2*x2 + mu
  ) %>% 
  summarise(
    beta1 = sum(z*y1)/sum(z*x1),
    beta2 = sum(z*y2)/sum(z*x2)
  )
beta_cb1[i] <- b[1,1]
beta_cb2[i] <- b[1,2]
}
data_frame(
  beta1 = beta_cb1 %>% unlist(),
  beta2 = beta_cb2 %>% unlist()
) %>% 
  gather() %>% 
  ggplot(aes(x = value, y = ..density..,col = key)) + 
    geom_freqpoly() +
    labs(
      x = "预测的beta值,真实为2",
      y = "频率",
      subtitle = "弱工具变量在小样本下很容易不对称,有偏",
      title = "弱工具变量比较"
    ) +
  theme_minimal() +
  theme(text = element_text(family = "STKaiti"))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): Windows字体数据
## 库里没有这样的字体系列
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): Windows字体数据
## 库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): Windows字体数据
## 库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, :
## Windows字体数据库里没有这样的字体系列

陈强. 2014. 高级计量经济学及Stata应用.第2版. 高等教育出版社.