SHAZAM Questions and Answers (Q&A) - RSS feedhttp://community.econometrics.com/questions/SHAZAM Econometrics, Statistics and Analytics Communityen<font color="white">Copyright <b>SHAZAM Analytics, 2018</b></font>Tue, 25 Sep 2012 00:31:07 +0000Creating variables from saved coefficientshttp://community.econometrics.com/question/246/creating-variables-from-saved-coefficients/Hi all,
Say I run 10 OLS simple regressions in a do-loop and I save the intercept and the slope of each regression with the COEF option. Been going crazy about this: How can I put the 10 intercepts saved into one vector (variable) and the 10 slopes saved into another vector (variable)??? Thanks in advance!Sat, 22 Sep 2012 16:16:51 +0000http://community.econometrics.com/question/246/creating-variables-from-saved-coefficients/Answer by David for <p>Hi all,
Say I run 10 OLS simple regressions in a do-loop and I save the intercept and the slope of each regression with the COEF option. Been going crazy about this: How can I put the 10 intercepts saved into one vector (variable) and the 10 slopes saved into another vector (variable)??? Thanks in advance!</p>
http://community.econometrics.com/question/246/creating-variables-from-saved-coefficients/?answer=332#post-id-332This can be done simply by DIMensioning the two vectors, saving the coefficient vector on each OLS and then using the COPY command to copy the coefficients to the locations in the vectors you desire.
Here is an example of doing this with some fake generated data.
* Disable detailed output information
set nodoecho
set noecho
* Dimension the output vectors to store the intercepts and coefficients
dim myinter 10
dim mycoeff 10
* Set our sample to 12 observations
sample 1 12
* Do 10 fake regressions and copy the results to a single vector
* N.B. Prefixing commands by ? hides their output
do(% = 1, 10)
* Generate 10 fake data sets for variables y and x
?genr y% = % + nor(1)
?genr x% = %-1 + 10 * nor(5)
* Perform a simple regression of y on x and a constant - save the coefficients
?ols y% x% / coeff=coeff%
print coeff%
* Copy the generated coefficient to the place in the vector we wish
copy coeff% myinter / frow=1;1 trow=%;%
copy coeff% mycoeff / frow=2;2 trow=%;%
endo
* Print the vectors
print myinter mycoeff
Tue, 25 Sep 2012 00:31:07 +0000http://community.econometrics.com/question/246/creating-variables-from-saved-coefficients/?answer=332#post-id-332