Dale Steele
>
> Given the dataset below, for each idnum, I would like to
> create two new
> variables which summarize the least squares relationship
> between lcresponse
> and lresistnc. Ie. newvar1=slope, newvar2 = y-intercept.
>
> The following command using "by" generates regression
> output for each idnum:
> by idnum: regress lcresponse lresistnc
>
> However, I'm stuck on how to save the slope '_b[lresistnc]'
> and yint '-b[_cons]' as new variables for each idnum.
>
> Thanks...
>
>
> idnum lcresponse lresistnc
> 1. 401 . .
> 2. 401 .3579348 .39794
> 3. 401 .5587085 .69897
> 4. 401 .6627578 1
> 5. 401 .888741 1.30103
> 6. 401 .923244 1.477121
> 7. 402 . .
> 8. 402 .0253059 .39794
> 9. 402 .071882 .69897
> 10. 402 .5658478 1
> 11. 402 .748188 1.30103
> 12. 402 .9314579 1.477121
> 13. 500 . .
> 14. 500 -.39794 .39794
> 15. 500 .2741579 .69897
> 16. 500 .4183013 1
> 17. 500 .7041505 1.30103
> 18. 500 .7512791 1.47712
> ...
>
I have some doubts on handing you a loaded gun, but
you can do this with
statsby "regress lcresponse lresistnc" _b , by(idnum)
If you want to keep these results in the same
data set, do something like
sort idnum
save main
statsby "regress lcresponse lresistnc" _b , by(idnum)
sort idnum
merge idnum using main
Nick
[email protected]
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/