SHAZAM Community
Ask Your Question

Creating variables from saved coefficients

asked 2012-09-22 16:16:51 +0000

jaeshazam gravatar image

updated 2012-09-25 00:32:52 +0000

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!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-09-25 00:31:07 +0000

David gravatar image

updated 2012-09-25 23:26:01 +0000

This 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=%;%


* Print the vectors
print myinter mycoeff
edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2012-09-22 16:16:51 +0000

Seen: 215 times

Last updated: Sep 25 '12