I have a quantile regression model as follows:
rqpdfit <- rqpd(cr1 ~ x1 + x2 + x3 + x4 + x5 + x6 +x7|id,
panel(lambda = 1,taus=c(0.1, 0.25, 0.5, 0.75, 0.9),tauw=rep(1/5, 5), method="pfe"),
data =pdata)
To produce output table, I divided results per quantile.
cf_10<- summary(rqpdfit)$coefficients[1:8,]
Here is the first quantile output:
Value Std. Error t value Pr(>|t|)
(Intercept)[0.1] 14.4864410152 11.670505897 1.24128647 2.145773e-01
> x1[0.1] -1.1081682804 1.230039754 -0.90092070 3.676881e-01
> x2[0.1] 0.5036482698 0.097472484 5.16708152 2.501200e-07
> x3[0.1] -0.8077127317 0.282774725 -2.85638234 4.308473e-03
> x4[0.1] 0.0006560821 0.008695294 0.07545255 9.398587e-01
> x5[0.1] -0.0102064486 0.043276674 -0.23584180 8.135683e-01
> x6[0.1] -0.1081589250 0.061636404 -1.75478966 7.937665e-02
> x7[0.1] -0.7891778648 0.251492587 -3.13797665 1.714334e-03
However, I don't know how I can extract coefficients and t-values in matrix (with significance stars if possible).
Thanks
You can check if the (unnamed) package you are using works with stargazer
, but otherwise, getting the stars won't be automatic. You usually can extract this info using summary()
.
# coefficients and t-values in matrix
cf_10 <- summary(x)$coefficients[1:8,c(1,3)]
# p-values
cf_10.pVals <- summary(x)$coefficients[1:8,4]
If you really want, you could implement an algorithm to paste stars onto the coefficients.
There is likely a prettier way, but this should be fairly straightforward to read:
# function to print stars
starPrinter <- function(pVal) {
if(pVal < 0.01) return("***")
if(pVal < 0.05) return("**")
if(pVal < 0.1) return("*")
return("")
}
# a matrix, with digits rounded to 3rd decimal
myTable <- round(cf_10, 3)
# get stars and put tvalues in parentheses
for(i in 1:nrow(myTable)) {
myTable[i, 1] <- paste0(myTable[i, 1], starPrinter(cf_10.pVals[i]))
myTable[i, 2] <- paste0("(", myTable[i, 2], ")")
}
If you want to make this a vector, where you have coef1, tval1, coef2, tval2...
myEstVector.cf_10 <- as.character(t(myTable))
You can then combine multiple results into a new table:
myNewTable <- cbind(myEstVector.cf_10, myEstVector.cf_25, myEstVector.cf_99)
Just trying to add to the above thread. I followed the code above and exported results into a csv file format.
# y is the dependent variable
# x6 is a vector of 6 independent variables.
#setting regression
r6.form <- y ~ x6 |as.factor(cty)
r6090 <- rqpd(r6.form, panel= panel(taus=c(0.1, 0.25, 0.5, 0.75, 0.9), tauw = rep(1/5,5)),
na.action = 'na.omit', data=mydata)
#Storing results
c6090 <- summary(r6090, se = "boot", R=1000, covariance = TRUE)
#making a data frame for results
df6 = as.data.frame(c6090$coefficients)
#coefficients and t-values in a matrix
cf_6 <- df6[1:71, c(1,3)]
#p-values
cf_6.pval <- df6[1:71,4]
#function to print stars
starPrinter <- function(pVal) {
if(pVal < 0.01) return("***")
if(pVal < 0.05) return("**")
if(pVal < 0.1) return("*")
return("")
}
# a matrix, with digits rounded to 3rd decimal
myTable6 <- round(cf_6, 3)
# get stars and put tvalues in parentheses
for(i in 1:nrow(myTable6)) {
myTable6[i, 1] <- paste0(myTable6[i, 1], starPrinter(cf_6.pval[i]))
myTable6[i, 2] <- paste0("(", myTable6[i, 2], ")")
}
#creating a vector
table.cf_6 <- (t(myTable6))
#exporting it to CSV file
write.table(table.cf_6, "c6090.csv", sep =',', row.names = TRUE)
This extracts results into different columns with variable names.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.