Sie sind auf Seite 1von 3

library(Magic) # Reading the dataset nerlov.csv maindata<-read.csv("C:\\Vishal\\Term 4\\Econometrics\\nerlove.

csv") #Retrieving data for first group d1 <- maindata[1:29,] #Retrieving data for second group d2 <- maindata[30:58,] #Retrieving data for third group d3 <- maindata[59:87,] #Retrieving data for fourth group d4<- maindata[88:116,] #Retrieving data for fifth group d5<- maindata[117:145,] # Regression for first group regd1 <- lm(log(TC/PF) ~ log(Q) # Regression for second group regd2 <- lm(log(TC/PF) ~ log(Q) # Regression for third group regd3 <- lm(log(TC/PF) ~ log(Q) # Regression for fourth group regd4 <- lm(log(TC/PF) ~ log(Q) # Regression for fifth group regd5 <- lm(log(TC/PF) ~ log(Q) + log(PL/PF) + log(PK/PF), data=d1) + log(PL/PF) + log(PK/PF), data=d2) + log(PL/PF) + log(PK/PF), data=d3) + log(PL/PF) + log(PK/PF), data=d4) + log(PL/PF) + log(PK/PF), data=d5)

# SSR of regression on first group ssrd1 = sum(resid(regd1)^2) # SSR of regression on second group ssrd2 = sum(resid(regd2)^2) # SSR of regression on third group ssrd3 = sum(resid(regd3)^2) # SSR of regression on fourth group ssrd4 = sum(resid(regd4)^2) # SSR of regression on fifth group ssrd5 = sum(resid(regd5)^2) # Sum of SSR Model1SSR= ssrd1 + ssrd2 + ssrd3 + ssrd4 + ssrd5 #Model 2 # Creating new data set from d1 logd1 <- d1 logd1[1] <- log(d1[2]) logd1[2] <- log(d1[3]) logd1[3] <- log(d1[4]) logd1[4] <- log(d1[5]) # Creating new data set from d2 logd2 <- d2 logd2[1] <- log(d2[2]) logd2[2] <- log(d2[3]) logd2[3] <- log(d2[4]) logd2[4] <- log(d2[5]) # Creating new data set from d3 logd3 <- d3 logd3[1] <- log(d3[2]) logd3[2] <- log(d3[3]) logd3[3] <- log(d3[4]) logd3[4] <- log(d3[5])

# Creating new data set from d4 logd4 <- d4 logd4[1] <- log(d4[2]) logd4[2] <- log(d4[3]) logd4[3] <- log(d4[4]) logd4[4] <- log(d4[5]) # Creating new data set from d5 logd5 <- d5 logd5[1] <- log(d5[2]) logd5[2] <- log(d5[3]) logd5[3] <- log(d5[4]) logd5[4] <- log(d5[5]) # Removing extra column from new datasets logd1[5] <- NULL logd2[5] <- NULL logd3[5] <- NULL logd4[5] <- NULL logd5[5] <- NULL # Block diagonal matrix formation LOGDX <- adiag(data.matrix(logd1), data.matrix(logd2), data.matrix(logd3), data .matrix(logd4), data.matrix(logd5)) #Dependent variable matrix Y <- log(maindata[1]) # LOGDX - matrix form LOGDX <- data.matrix(LOGDX) # Y - matrix form Y <- data.matrix(Y) # Finding Beta Vecor Model2Beta <- solve(t(LOGDX)%*% LOGDX)%*% t(LOGDX)%*% Y # Finding Residual Vector Model2Resi <- Y - LOGDX %*% Model2Beta # Unrestricted SSR- Model 2 Model2SSR = sum(Model2Resi ^2) #plotting residuals against log(Q) plot(t(log(maindata[2])), t(Model2Resi), ylab="Residuals", xlab="Log Output")

#Model 3 # Creating new data set from d1 D1<- d1 D1[1] <- 1 D1[2] <- log(d1[2]) #Keeping only first two columns D1 <- D1[,c(1:2)] # Creating new data set from d2 D2<- d2 D2[1] <- 1

D2[2] <- log(d2[2]) #Keeping only first two columns D2 <- D2[,c(1:2)] # Creating new data set from d3 D3<- d3 D3[1] <- 1 D3[2] <- log(d3[2]) #Keeping only first two columns D3 <- D3[,c(1:2)] # Creating new data set from d4 D4<- d4 D4[1] <- 1 D4[2] <- log(d4[2]) #Keeping only first two columns D4 <- D4[,c(1:2)] # Creating new data set from d5 D5<- d5 D5[1] <- 1 D5[2] <- log(d5[2]) #Keeping only first two columns D5 <- D5[,c(1:2)] #Block diagonal matrix D <- adiag(data.matrix(D1), data.matrix(D2), data.matrix(D3), data.matrix(D4), data.matrix(D5)) D <- data.frame(D) # Adding new column- log[PL/PF] D[11] <- log(maindata[3]/maindata[4]) # Adding new column- log[PK/PF] D[12] <- log(maindata[5]/maindata[4]) #Regressor matrix D <- data.matrix(D) #Independent variable vector Y <- data.matrix(Y) # Finding beta vector Model3Beta <- solve(t(D)%*% D)%*% t(D)%*% Y #Finding residuals Model3Resi <- Y- D %*% Model3Beta #plotting residuals against log(Q) plot(t(log(maindata[2])), t(Model3Resi), ylab="Residuals", xlab="Log Output")