Dow and Eff Simple Functions Vers 0

From InterSciWiki
Jump to: navigation, search
#--Dow & Eff simple functions for CoSsci-- #Install packages listed below
rm(list=ls(all=TRUE));gc()
setwd("e:/Dropbox/functions")
library(mice)
library(foreign)
library(stringr)
library(psych)
library(AER)
library(spdep)
# ================================
# --bring in functions and data--
# ================================
load(url("http://dl.dropbox.com/u/9256203/DE7.Rdata"),.GlobalEnv)
ls() #-can see the objects contained in DE7.Rdata
# ================================
#--list and modify variables for use in model-- 
# ================================
sccsA$valchild=(sccsA$v473+sccsA$v474+sccsA$v475+sccsA$v476)
sccsA$roots=(sccsA$v233==5)*1
sccsA$milk=(sccsA$v245>1)*1
sccsA$bovines=(sccsA$v244==7)*1
sccsA$tree=(sccsA$v233==4)*1
sccsA$himilexp=(sccsA$v899==1)*1
evm<-c("socname","v203","v204","v1685","v156","v72","v234","v236","v238","v1648",
      "v155","roots","milk","bovines","tree","himilexp","valchild")
a<-sccsAkey[evm,];a[grep("catego",a$varbtype),] #make sure variables are ordinal
# ================================
# --make imputed data--
# ================================
smi<-doMI(evm,nimp=2,maxit=3);dim(smi)
smi[1:2,]
# ================================
# --identify variables for model--
# ================================
# --dependent variable--
depvar<-"valchild"
#--independent variables in UNrestricted model--
indpv<-c("v203","v204","v1685","v156","v72","v234","v236","v238","v1648",
        "v155","roots","milk","bovines","tree","himilexp")
#--additional exogenous variables (use in Hausman tests)--
othexog<-c(paste("bio.",1:19,sep=""),"meanalt","mnnpp")
#--independent variables in restricted model--
rindpv<-c("v155","roots","milk","bovines","tree","himilexp")
# ================================
# --estimate regression model-----
# ================================
h<-doOLS(smi,depvar,indpv,rindpv=NULL,othexog=NULL,
        dw=TRUE,lw=TRUE,rw=FALSE,ew=FALSE,stepW=FALSE,
        relimp=FALSE,slmtests=FALSE)
print(h)
# ================================
# --print output to csv file--
# ================================
CSVwrite(names(h),"olsresults",FALSE)
CSVwrite(h,"olsresults",TRUE)