美文网首页
面板数据回归的R命令

面板数据回归的R命令

作者: 明明就_faf8 | 来源:发表于2019-08-26 21:15 被阅读0次

    参考一:https://www.cnblogs.com/laoketeng/p/11268581.html

    library(plm)
    
    library(psych)
    
    library(xts)
    
    library(tseries)
    
    library(lmtest)
    
     
    
    ## import dataset
    
    datas<-read.table("data.txt",header =TRUE)
    
     
    
    ## adf test
    
    pcgdp<-xts(datas$PCGDP,as.Date(datas$year))
    
    adf.test(pcgdp)
    
    # result: stationary
    
     
    
    ltax<-xts(datas$Ltax,as.Date(datas$year))
    
    adf.test(ltax)
    
    # result: stationary
    
     
    
    hp<-xts(datas$hp,as.Date(datas$year))
    
    adf.test(hp)
    
    # result: stationary
    
     
    
    lp<-xts(datas$lp,as.Date(datas$year))
    
    adf.test(lp)
    
    # result: stationary
    
     
    
    ## 协整检验
    
    # Engle-Granger
    
    reg<-lm(datas$hp~datas$lp+datas$Ltax+datas$PCGDP)
    
    summary(reg)
    
    error<-residuals(reg)
    
    adf.test(error)
    
    # result: residuals stationary
    
     
    
    ### 面板数据回归
    
    hpdatas<-plm.data(datas,index=c("city","year"))
    
     
    
    # Pooled Regression Model
    
    hp_pool<-plm(hp~lp+Ltax+PCGDP+PP,data=hpdatas,model = "pooling")
    
     
    
    # Fixed Effects Regression Model
    
    hp_fe<-plm(hp~lp+Ltax+PCGDP+PP,data=hpdatas,model = "within")
    
     
    
    # F-test :
    
    pFtest(hp_fe,hp_pool)
    
    # result: significant effects
    
     
    
    # Random Effects Regression Model
    
    
    hp_re<-plm(hp~lp+Ltax+PCGDP,data=hpdatas,model="random",random.method = "swar")
    
               
    
    # Hausman test
    
    phtest(hp_fe,hp_re)
    
    # if p<0.05,then use fixed effects
    
    # result: p=0.6785>0.05,use random ffects
    
    
    # Random Effects Regression Model
    
    hp_re<-plm(hp~lp+Ltax+PCGDP,data=hpdatas,model="random",random.method = "swar")
    
    summary(hp_re)
    
    # 显著水平 a=0.01
    
    # result: fp:房价与 lp:地价正相关,且显著; 
    
    #         fp:房价与 Ltax: 地税收入正相关,且显著; 
    
    #         fp:房价与 PCGDP: 人均GDP 正相关,且显著;
    

    参考二:https://zhuanlan.zhihu.com/p/24877529

    Panel Data Models in R

    library(plm)
    mydata <- read.csv("panel_wage.csv")
    attach(mydata)
    Y <- cbind(lwage)
    X <- cbind(exp, exp2, wks, ed)

    summary(Y)
    summary(X)

    ols <- lm(Y ~ X)
    summary(ols)

    声明面板

    Stata: xtset

    pdata <- plm.data(mydata,indexes = c("id","t"))

    混合回归

    Stata: reg

    pooling <- plm(Y ~ X, data = pdata,model = "pooling")
    summary(pooling)

    固定效应

    Stata: xtreg ,fe

    fixed <- plm(Y ~ X,data = pdata,model = "within")
    summary(fixed)

    随机效应

    Stata: xtreg ,re

    random <- plm(Y ~ X,data = pdata,model = "random")
    summary(random)

    不同模型的比较

    random vs ols

    plmtest(pooling)

    fixed vs ols

    pFtest(fixed, pooling)

    random vs fixed

    phtest(random, fixed)

    相关文章

      网友评论

          本文标题:面板数据回归的R命令

          本文链接:https://www.haomeiwen.com/subject/cchjectx.html