Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # 09-04-2014
- # Test script estimation of spatial model
- # Code taken from Jamie Monogan:
- # http://monogan.myweb.uga.edu/teaching/spatial/fhReplication.R
- # Replication material from:
- # Franzese and Hays. 2007.
- # "Spatial Econometric Models of Cross-Sectional Interdependence in
- # Political Science Panel and Time-Series-Cross-Section Data."
- # Political Analysis 15:140-164.
- #==============================================================================
- # Set preferences
- options(scipen=10)
- # Load data
- fh<-read.csv('~/Desktop/almMLire.csv',header=TRUE) # Dataset
- adj<-as.matrix(read.csv('~/Desktop/almWeights.csv',header=FALSE)) # Adjacency matrix
- # Row-standardize adjacency matrix
- noNeigh<-apply(adj,1,sum)
- noNeigh[7]<-.01 # Greece has no neighbours, adjust as we can't have 0 in the denominator
- wmat<-adj/noNeigh # Spatial weight matrix
- # Calculate spatial lag of outcome variable, using Kronekcer product
- N<-length(unique(fh$cc))
- T<-length(unique(fh$year))
- ident<-diag(1,nrow=T) # Identity matrix
- bigW<-(ident%x%wmat)
- fh$SpatLag<-(ident%x%wmat)%*%fh$lnlmtue # Spatial lag
- ## REPLICATE TABLE 4
- # Column 1. Simple OLS model
- m1<-lm(lnlmtue~lnlmtue_1+DENSITY+DEIND+lngdp_pc+UR+TRADE+FDI+LLVOTE+LEFTC+
- TCDEMC+GOVCON+OLDAGE+
- as.factor(cc)+as.factor(year),
- data=fh);summary(m1)
- # Gives roughly the same results as in the paper
- # Column 2. OLS model including a spatial lag
- m2<-lm(lnlmtue~lnlmtue_1+SpatLag+DENSITY+DEIND+lngdp_pc+UR+TRADE+FDI+LLVOTE+LEFTC+
- TCDEMC+GOVCON+OLDAGE+
- as.factor(cc)+as.factor(year),
- data=fh);summary(m2)
- # Again roughly the same results
- # Column 3. Spatial 2SLS
- # Spatially lag all the explanatory variables
- fh$l.lnlmtue_1<-(ident%x%wmat)%*%fh$lnlmtue_1
- fh$l.DENSITY<-(ident%x%wmat)%*%fh$DENSITY
- fh$l.DEIND<-(ident%x%wmat)%*%fh$DEIND
- fh$l.lngdp_pc<-(ident%x%wmat)%*%fh$lngdp_pc
- fh$l.UR<-(ident%x%wmat)%*%fh$UR
- fh$l.TRADE<-(ident%x%wmat)%*%fh$TRADE
- fh$l.FDI<-(ident%x%wmat)%*%fh$FDI
- fh$l.LLVOTE<-(ident%x%wmat)%*%fh$LLVOTE
- fh$l.LEFTC<-(ident%x%wmat)%*%fh$LEFTC
- fh$l.TCDEMC<-(ident%x%wmat)%*%fh$TCDEMC
- fh$l.GOVCON<-(ident%x%wmat)%*%fh$GOVCON
- fh$l.OLDAGE<-(ident%x%wmat)%*%fh$OLDAGE
- # First stage regression
- stage.1<-lm(SpatLag~l.lnlmtue_1+l.DENSITY+l.DEIND+l.lngdp_pc+l.UR+l.TRADE+l.FDI+l.LLVOTE+
- l.LEFTC+l.TCDEMC+l.GOVCON+l.OLDAGE, data=fh);summary(stage.1)
- # Write predicted values to variable
- fh$iv.Lag<-stage.1$fitted.values
- # Second stage estimation
- m3<-lm(lnlmtue~lnlmtue_1+iv.Lag+DENSITY+DEIND+lngdp_pc+UR+TRADE+FDI+LLVOTE+
- LEFTC+TCDEMC+GOVCON+OLDAGE+
- as.factor(cc)+as.factor(year),
- data=fh);summary(m3)
- # Slightly different results, this is possibly due to the fact that not all Xs were
- # modelled in the first stage. Close enough anyway.
- # Column 4. Spatial Maximum Likelihood (GLM model)
- require(MASS)
- m4<-glm(lnlmtue~lnlmtue_1+SpatLag+DENSITY+DEIND+lngdp_pc+UR+TRADE+FDI+LLVOTE+LEFTC+
- TCDEMC+GOVCON+OLDAGE+
- as.factor(cc)+as.factor(year),family=gaussian,
- data=fh);summary(m4)
- # Can see that there is quite some difference in the estimates
- # Probably not the right ML estimator
- # Try estimating the model with 'spml'
- # NB - using FE not possible
- require(splm)
- m4a<-spml(lnlmtue~lnlmtue_1+DENSITY+DEIND+lngdp_pc+UR+TRADE+FDI+LLVOTE+LEFTC+
- TCDEMC+GOVCON+OLDAGE,data=fh,index=c("cc","year"),listw=mat2listw(wmat),
- model="pooling",spatial.error="none",lag=T);summary(m4a)
- # Results are quite different
Advertisement
Add Comment
Please, Sign In to add comment