如何计算R中的弹性系数?例如,从数据集nlsw88中计算样本中所有女性的任期工资弹性
h <- read.dta("nlsw88.dta")
h1 <- mutate(h, age = log(h$age), wage = log(h$wage))
model2 <- lm(data = h1,
wage ~ age + race + married + never_married + grade + collgrad + industry + union + occupation + hours + ttl_exp + tenure + c_city)我用这个公式来计算弹性
elas1<-as.numeric(model2$coefficients["age"]*mean(h1$age)/mean(h1$wage))
-0.2217391但是使用这个公式,我不能计算“竞速”弹性,因为它不是数值的,如果我把elas3<-as.numeric(model2$coefficients["hours"]*mean(h1$hours)/mean(h1$wage)),写成NA_real_
怎么了?
发布于 2017-04-24 02:10:04
当你不包括任何可重复的例子时,很难给出一个准确的答案,但这里有一个关于如何计算需求弹性的例子:
# Create a data
df = data.frame(sales = c(18,20,22,23), Price=c(4.77,4.67,4.75,4.74))
# Run regression
formula = lm(sales~., data=df)
# Get the summary of the regression
summary(formula)
#Call:
#lm(formula = sales ~ ., data = df)
#Residuals:
# 1 2 3 4
#-2.6344 -0.9427 1.3040 2.2731
#Coefficients:
# Estimate Std. Error t value Pr(>|t|)
#(Intercept) 35.344 170.297 0.208 0.855
#Price -3.084 35.983 -0.086 0.940为了计算需求弹性,我们使用以下公式: PE = (ΔQ/ΔP) * (P/Q)
(ΔQ/ΔP)由我们的回归公式中的系数-3.084决定。
为了确定(P/Q),我们将使用平均价格(4.73)和平均销售额(20.75)。
The PE = -3.084 * 4.73/20.75 = -0.70
formula$coefficients["Price"]*mean(df[,2])/mean(df[,1])
# -0.7033066 这意味着给定产品的价格每上涨1个单位,在你的情况下,工资将减少0.70个单位的销售额。
希望能有所帮助
https://stackoverflow.com/questions/43572657
复制相似问题