I am going to do two things in STATA: (1) loop a regression over a certain criteria for many times; (2) store a certain coefficient from each regression results. I am giving an example of what I am doing below:
As to all stored regression coefficients results, I actually just care about one of them, for example, mpg here. Ideally, I want STATA to extract coefficients of mpg from each result and compile them into one independent file(any file is OK, .dta would be great). By doing this, I want to see the trend of coefficient of `mpg` as `weight` increases. What I am doing right now is to use`estout` to export the results, something like:
`estout` will export everything and I need to edit them by myself. Technically, It works for regressions with smaller amount of independent variables, but my real working dataset has more than 30 variables and the regression will loop for at least 100 times ( I have a variable `Distance` which is in a range of (0 ~ 30,000) and I use it as `weight` as in the above example). Therefore, it is really difficult for me to edit the results by myself without making mistakes.
I am wondering are there any other efficient ways to solve my problem? especially the second one. I definitely would like to know a silver bullet method (if there is one) to solve them both at one time. Since my case is not looping over a group variable, but over a certain criteria. The `statsby` function seems not working well here. Any comments or suggestions are greatly appreciated!
Code:
clear sysuse auto.dta local x = 2000 while `x' < 5000{ xi: regress price mpg length gear_ratio i.foreign if weight < `x' est sto model_`x' local x = `x' + 100 } est dir
Code:
esttab * using test.rtf, replace se stats(r2_a N, labels(R-squared)) starl(* 0.10 ** 0.05 *** 0.01) nogap onecell title(regression tables)
I am wondering are there any other efficient ways to solve my problem? especially the second one. I definitely would like to know a silver bullet method (if there is one) to solve them both at one time. Since my case is not looping over a group variable, but over a certain criteria. The `statsby` function seems not working well here. Any comments or suggestions are greatly appreciated!
Comment