Including Confidence Interval on a Line in an Array

1

I want to create an array of 38 rows and two columns with coefficients in the odd rows and the confidence intervals for the parameters in even rows.

Then call stargazer .

My code is:

library(quantreg)

y <- rnorm(200)
x <- matrix(rnorm(123),200)
fit <- rq(y~x,tau=seq(0.05, 0.95, by = 0.05),method="br")

summary(fit,se="nid")

I've been able to move this far:

Notice that I can put the coefficients on even odd rows. The obvious error is when I try to construct and put the parameter confidence interval on even lines:

fit_Matrix<-matrix(0,38,2)

for(i in 1:19) for (j in seq(1, 38, by = 2)[i]) for (k in seq(2, 38, by = 2)[i]) { 

fit_Matrix[j,1]<-summary(fit,se="nid")[[i]]$coefficients[1]
fit_Matrix[j,2]<-summary(fit,se="nid")[[i]]$coefficients[2]

fit_Matrix[k,1]<-summary(fit,se="nid")[[i]]$coefficients[1]-1.645*summary(fit,se="nid")[[i]]$coefficients[3]; 
summary(fit,se="nid")[[i]]$coefficients[1]+1.645*summary(fit,se="nid")[[i]]$coefficients[3]

fit_Matrix[k,2]<-summary(fit,se="nid")[[i]]$coefficients[2]-1.645*summary(fit,se="nid")[[1]]$coefficients[4];
summary(fit,se="nid")[[i]]$coefficients[2]-1.645*summary(fit,se="nid")[[i]]$coefficients[4]

}

The second part of the code is wrong. How do I fix it? Remembering that you would like to transport the array to LaTeX.

Thank you in advance.

    
asked by anonymous 04.08.2016 / 20:54

1 answer

1

Here is my suggestion for an answer. My code got a bit pork, slow and ugly, but I'm in a bit of a hurry.

library(quantreg)

y   <- rnorm(200)
x   <- matrix(rnorm(123), 200)
fit <- rq(y~x, tau=seq(0.05, 0.95, by = 0.05), method="br")

summary(fit, se="nid")

fit_Matrix <- matrix(NA, 38, 4)
index.coef <- seq(1, 37, 2)
index.ic   <- seq(2, 38, 2)

fit_Matrix[index.coef, 1] <- fit$coefficients[1, ]
fit_Matrix[index.coef, 3] <- fit$coefficients[2, ]

mult <- 1.645
i    <- 1

for (j in index.ic){

  fit_Matrix[j, 1] <- unlist(summary(fit, se="nid")[[i]][3][1])[1] - mult*unlist(summary(fit, se="nid")[[i]][3][1])[3]
  fit_Matrix[j, 2] <- unlist(summary(fit, se="nid")[[i]][3][1])[1] + mult*unlist(summary(fit, se="nid")[[i]][3][1])[3]
  fit_Matrix[j, 3] <- unlist(summary(fit, se="nid")[[i]][3][1])[2] - mult*unlist(summary(fit, se="nid")[[i]][3][1])[4]
  fit_Matrix[j, 4] <- unlist(summary(fit, se="nid")[[i]][3][1])[2] + mult*unlist(summary(fit, se="nid")[[i]][3][1])[4]

  i <- i+1

}

fit_Matrix

I could not check the accounts, but I think they're all right.

    
04.08.2016 / 22:06