library( systemfit )
data( kmenta )
attach( kmenta )
demand <- q ~ p + d
supply <- q ~ p + f + a
inst <- ~ d + f + a
labels <- list( "demand", "supply" )
system <- list( demand, supply )
## perform 2SLS on each of the equations in the system
fit2sls <- systemfit( "2SLS", system, labels, inst)
print( fit2sls )
print( fit2sls$rcov )
## perform the 3SLS
fit3sls <- systemfit( "3SLS", system, labels, inst )
print( fit3sls )
print( "covariance of residuals used for estimation (from 2sls)" )
print( fit3sls$rcovest )
print( "covariance of residuals" )
print( fit3sls$rcov )
## examine the correlation between the predicted values
## of suppy and demand by plotting the correlation over
## the value of q
r12 <- correlation.systemfit( fit3sls, 1, 2 )
plot( q, r12, main="correlation between predictions from supply and demand" )
Run the code above in your browser using DataLab