library( systemfit ) data( kmenta ) # q food consumption per capita. # p ratio of food prices to general consumer prices. # d disposable income in constant dollars. # f ratio of preceding year's prices received by farmers to general # consumer prices. # a time in years. demand <- q ~ p + d supply <- q ~ p + f + a labels <- list( "demand", "supply" ) system <- list( demand, supply ) ## OLS estimation fitols <- systemfit("OLS", system, labels, data=kmenta ) print( fitols ) ## OLS estimation with 2 restrictions Rrestr <- matrix(0,2,7) qrestr <- matrix(0,2,1) Rrestr[1,3] <- 1 Rrestr[1,7] <- -1 Rrestr[2,2] <- -1 Rrestr[2,5] <- 1 qrestr[2,1] <- 0.5 Rrestr # 0 0 1 0 0 0 -1 # 0 -1 0 0 1 0 0 qrestr # 0.0 # 0.5 #Rb=q ,means b3-b7=0 and b5-b2=0.5 are two restrictions fitols2 <- systemfit("OLS", system, labels, data=kmenta, R.restr=Rrestr, q.restr=qrestr ) print( fitols2 ) ## iterated SUR estimation fitsur <- systemfit("SUR", system, labels, data=kmenta, maxit=100 ) print( fitsur ) ## 2SLS estimation inst <- ~ d + f + a fit2sls <- systemfit( "2SLS", system, labels, inst, kmenta ) print( fit2sls ) ## 2SLS estimation with different instruments in each equation inst1 <- ~ d + f inst2 <- ~ d + f + a instlist <- list( inst1, inst2 ) fit2sls2 <- systemfit( "2SLS", system, labels, instlist, kmenta ) print( fit2sls2 ) ## 3SLS estimation with GMM-3SLS formula inst <- ~ d + f + a fit3sls <- systemfit( "3SLS", system, labels, inst, kmenta, formula3sls="GMM" ) print( fit3sls ) How to do the Klein I model with systemfit software? Unsolved problem: Some Hints: library( systemfit ) data( klein ) p.lag <- c(NA, p[-length(p)]) x.lag <- c(NA, x[-length(x)]) a <- year - 1931 cbind(year, a, p, p.lag, x, x.lag) #NEED to write system of equations. Should it be 3 or include definitional #identities? eqn.1 <- tsls(c ~ p + p.lag + I(wp + wg), instruments= ~ g + t + wg + a + p.lag + k.lag + x.lag) summary(eqn.1) eqn.2 <- tsls(i ~ p + p.lag + k.lag, instruments= ~ g + t + wg + a + p.lag + k.lag + x.lag) summary(eqn.2)