I'm running an lm() on lagged variables as part of a network analysis, and have the following dimensions:
dim(final)[1] 197 277dim(final_lag)[1] 197 831
The final dataset contains the non-lagged variables (with each row being a date and each column being a company). The final_lag dataset contains the 3 lags of each company (hence 197 days of 277 companies x 3 lags). I'm trying to run the following:
weights <-matrix(ncol = ncol(final), nrow=ncol(final_lag)) for(i in 1:ncol(final)){ #Beta estimation from OLS weights[,i] <- coef(lm(final[,i] ~ scale(final_lag)))[-1] print(i) }
However, in my weights results matrix which is 831 x 277, I only have coefficients for rows 1-196 while 197-831 are all NAs. If I change the number of rows in final, then I get numeric coefficients again until nrow(final) is hit. Anyone know how to fix this issue/why this is occurring? Thanks.