0

lm()で推計されたモデルの(経済的)弾力性を計算する関数があるのだろうか。

独立変数が平均 X を超えて 1% 変化した場合の、従属変数の平均 Y 付近のパーセンテージ変化に対する弾力性は、次のように計算されます。 b*X/Y (b= 独立変数のモデル係数)。

以下は、単純な線形モデルと各係数の弾力性を含む Rmd ファイルのコードです。出力は、変数名と弾力性の表になります。

---
title: "Elasticity"
output: html_document
---

```{r}
N <- 1000
u <- rnorm(N)
x1 <- rnorm(N)
x2 <- 1 + x1 + rnorm(N)
y <- 1 + x1 + x2 + u
df <- data.frame(y,x1,x2)

fit <- lm(y ~ x1 + x2, data = df)

elax1 <- as.numeric(fit$coefficients["x1"] * mean(df$x1)/mean(df$y))
elax2 <- as.numeric(fit$coefficients["x2"] * mean(df$x2)/mean(df$y))

variable <-c ('x1','x2')
elasticity <-c (elax1,elax2)
a <- data.frame(variable,elasticity)

```

Output the results in a table:

```{r, message=FALSE,results='asis'}
require(stargazer)
stargazer(a, summary = FALSE,type = 'html',rownames=FALSE)
```
4

1 に答える 1