Guest User

Replicating Franzese & Hays

a guest
Apr 10th, 2014
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 3.60 KB | None | 0 0
  1. #==============================================================================
  2. # 09-04-2014
  3. # Test script estimation of spatial model
  4. # Code taken from Jamie Monogan:
  5. # http://monogan.myweb.uga.edu/teaching/spatial/fhReplication.R
  6. # Replication material from:
  7. # Franzese and Hays. 2007.
  8. # "Spatial Econometric Models of Cross-Sectional Interdependence in
  9. # Political Science Panel and Time-Series-Cross-Section Data."
  10. # Political Analysis 15:140-164.
  11. #==============================================================================
  12.  
  13. # Set preferences
  14. options(scipen=10)
  15.  
  16. # Load data
  17. fh<-read.csv('~/Desktop/almMLire.csv',header=TRUE) # Dataset
  18. adj<-as.matrix(read.csv('~/Desktop/almWeights.csv',header=FALSE)) # Adjacency matrix
  19.  
  20. # Row-standardize adjacency matrix
  21. noNeigh<-apply(adj,1,sum)
  22. noNeigh[7]<-.01 # Greece has no neighbours, adjust as we can't have 0 in the denominator
  23. wmat<-adj/noNeigh # Spatial weight matrix
  24.  
  25. # Calculate spatial lag of outcome variable, using Kronekcer product
  26. N<-length(unique(fh$cc))
  27. T<-length(unique(fh$year))
  28. ident<-diag(1,nrow=T) # Identity matrix
  29. bigW<-(ident%x%wmat)
  30. fh$SpatLag<-(ident%x%wmat)%*%fh$lnlmtue # Spatial lag
  31.  
  32. ## REPLICATE TABLE 4
  33.  
  34. # Column 1. Simple OLS model
  35.  
  36. m1<-lm(lnlmtue~lnlmtue_1+DENSITY+DEIND+lngdp_pc+UR+TRADE+FDI+LLVOTE+LEFTC+
  37.          TCDEMC+GOVCON+OLDAGE+
  38.          as.factor(cc)+as.factor(year),
  39.               data=fh);summary(m1)
  40.  
  41. # Gives roughly the same results as in the paper
  42.  
  43. # Column 2. OLS model including a spatial lag
  44. m2<-lm(lnlmtue~lnlmtue_1+SpatLag+DENSITY+DEIND+lngdp_pc+UR+TRADE+FDI+LLVOTE+LEFTC+
  45.          TCDEMC+GOVCON+OLDAGE+
  46.          as.factor(cc)+as.factor(year),
  47.               data=fh);summary(m2)
  48.  
  49. # Again roughly the same results
  50.  
  51. # Column 3. Spatial 2SLS
  52.  
  53. # Spatially lag all the explanatory variables
  54. fh$l.lnlmtue_1<-(ident%x%wmat)%*%fh$lnlmtue_1
  55. fh$l.DENSITY<-(ident%x%wmat)%*%fh$DENSITY
  56. fh$l.DEIND<-(ident%x%wmat)%*%fh$DEIND
  57. fh$l.lngdp_pc<-(ident%x%wmat)%*%fh$lngdp_pc
  58. fh$l.UR<-(ident%x%wmat)%*%fh$UR
  59. fh$l.TRADE<-(ident%x%wmat)%*%fh$TRADE
  60. fh$l.FDI<-(ident%x%wmat)%*%fh$FDI
  61. fh$l.LLVOTE<-(ident%x%wmat)%*%fh$LLVOTE
  62. fh$l.LEFTC<-(ident%x%wmat)%*%fh$LEFTC
  63. fh$l.TCDEMC<-(ident%x%wmat)%*%fh$TCDEMC
  64. fh$l.GOVCON<-(ident%x%wmat)%*%fh$GOVCON
  65. fh$l.OLDAGE<-(ident%x%wmat)%*%fh$OLDAGE
  66.  
  67. # First stage regression
  68. stage.1<-lm(SpatLag~l.lnlmtue_1+l.DENSITY+l.DEIND+l.lngdp_pc+l.UR+l.TRADE+l.FDI+l.LLVOTE+
  69.               l.LEFTC+l.TCDEMC+l.GOVCON+l.OLDAGE, data=fh);summary(stage.1)
  70.  
  71. # Write predicted values to variable
  72. fh$iv.Lag<-stage.1$fitted.values
  73.  
  74. # Second stage estimation
  75. m3<-lm(lnlmtue~lnlmtue_1+iv.Lag+DENSITY+DEIND+lngdp_pc+UR+TRADE+FDI+LLVOTE+
  76.          LEFTC+TCDEMC+GOVCON+OLDAGE+
  77.          as.factor(cc)+as.factor(year),
  78.               data=fh);summary(m3)
  79.  
  80. # Slightly different results, this is possibly due to the fact that not all Xs were
  81. # modelled in the first stage. Close enough anyway.
  82.  
  83. # Column 4. Spatial Maximum Likelihood (GLM model)
  84. require(MASS)
  85. m4<-glm(lnlmtue~lnlmtue_1+SpatLag+DENSITY+DEIND+lngdp_pc+UR+TRADE+FDI+LLVOTE+LEFTC+
  86.          TCDEMC+GOVCON+OLDAGE+
  87.          as.factor(cc)+as.factor(year),family=gaussian,
  88.               data=fh);summary(m4)
  89.  
  90. # Can see that there is quite some difference in the estimates
  91. # Probably not the right ML estimator
  92.  
  93. # Try estimating the model with 'spml'
  94. # NB - using FE not possible
  95. require(splm)
  96. m4a<-spml(lnlmtue~lnlmtue_1+DENSITY+DEIND+lngdp_pc+UR+TRADE+FDI+LLVOTE+LEFTC+
  97.          TCDEMC+GOVCON+OLDAGE,data=fh,index=c("cc","year"),listw=mat2listw(wmat),
  98.           model="pooling",spatial.error="none",lag=T);summary(m4a)
  99.  
  100. # Results are quite different
Advertisement
Add Comment
Please, Sign In to add comment