I looking for a way to estimate various models (lets say 10) and save a certain parameter value from each estimation in a vector with stata.
Im more of a R-guy and here it is very simple working example with R-code
n1 <- 100
n2 <- 10
group <- rep(1:10,each=n1)
data <- as.data.frame(cbind(rnorm(n1*n2,0,1),rnorm(n1*n2,0,1),group))
dimnames(data)[[2]] <- c("y","x","group")
val <- names(table(group))
estimates <- vector(mode="numeric",length=length(val))
for( i in 1:length(val)){
j <- which(data$group==val[i])
estimates[i] <- coef(lm(y[j] ~ x[j], data=data))[2]
}
Alternatively
library(nlme)
mod1 <- lmList(y~x | group, data=data)
coef(mod1)[,2]
And yes, unfortunately I need to use stata 🙁
What is you ultimate objective? The paradigms of Stata and R are different, so knowing the ultimate goal would help. In R I tend to think in terms of vectors, but not in Stata (vectors don’t really exist in Stata). If you want a table, then I suggest the
estoutpackage from SSC (ssc install estout). If just want the coefficients as an end in themselves, then I suggeststatsby.Both
esttabandstatsbyhave lots of options, so check out the help files.Update: It seems you want time series betas by group (here a firm). In terms of economics I think you would want rolling regressions, but this framework should get you started.