Code Error for econometrics formula

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Code Error for econometrics formula

strains
I'm trying to exclude the one variable X2 and enter Xnew into the equation but keep getting this...
library(mvtnorm)
>   trueBeta = c(5,8,4,9)
>   n = 1000;
>   numSamp = 1000;
>   epsilon = matrix(rnorm(n*numSamp),n)
>   xCovar = matrix(c(1,1.5,1.5,3),2,2)
>   X = cbind(rep(1,n),rmvnorm(n, cbind(1,2),xCovar), runif(n, min = 0, max = 10))
>   k = ncol(X)
>   Xnew = cbind(X[,1],X[,3],X[,4])
>   y = matrix(0,n,numSamp)
>   beta_ols = matrix(0,k,numSamp)
>
>    
>    for (it in 1:numSamp) {
+      y[,it] = X%*%trueBeta + epsilon[,it]
+   beta_ols[,it] = solve(t(Xnew)%*%Xnew)%*%t(Xnew)%*%y[,it]}
Error in beta_ols[, it] = solve(t(Xnew) %*% Xnew) %*% t(Xnew) %*% y[,  :
  number of items to replace is not a multiple of replacement length