Hello,
i have dataset like this:
dat <- data.frame(
value = c(1.0,0.9,0.8,0.6,0.3,0.0,0.5,0.6,0.8,0.9,0.5,0.4),
var1 = c(1,0,1,0,0,0,1,0,0,1,1,1),
var2 = c(0,1,0,1,0,0,0,1,1,1,1,0),
var3 = c(0,1,1,1,0,1,1,1,1,1,1,0)
)
Before, I converted all the original categorical variables to binary variables (var1-var50) in the first step, because I think I can somehow move forward with such a dataset.
Now, I have many variables in columns (more than 50) and I would like to calculate descriptive statistics for the variable "value" for every categorical variable in place (number of observations, mean, 95pct, etc.). In other words, if the categorical (now binary) variable is = 1. Something like this:
no. mean 95pct
var 1 x x x
var 2 x x x
var 3 x x x
Thus, i would like to have variables in rows and descriptive statistics of variable "value" in columns (number of observations, mean, 95pct.) if the particular variable varx appplies.
I suppose I will have to use some for function (some loop) and then bind the results into one table. I would then ideally like to save such a table and perhaps put it into a document using the stargazer package (or something like this).
Thanks
Jan