Bryan,
bysort id : regress v1 time
[bysort will first sort the data by the id variable and then repeat the
regression command by each id]
For a lot of problem you do not need to use explicit looping in Stata. See
[R] by, [U] 14 Language syntax and Nick Cox's Speaking Stata columns
"Speaking Stata: How to repeat yourself without going mad" Stata Journal
(2001) 1:1 and "Speaking Stata: How to move step by: step" Stata Journal
(2002) 2:1.
Scott Merryman
----- Original Message -----
From: "Bryan Chung" <[email protected]>
To: <[email protected]>
Sent: Friday, July 19, 2002 2:49 PM
Subject: st: Linear regression for individual subjects
> I have a dataset that contains pain scores for people with heel pain. We
> measured heel pain at 0, 2, 4, 6, and 12 weeks post-initiation of
> treatment for heel pain. My data is organized such that I have six
> variables: ID, time (which has the values 0, 2, 4, 6, and 12), and the
> four pain scores (V1, V2, V3, and V4). What I am trying to do is to fit
> a line for each pain score for each ID over time (i.e. pain score vs.
> time). However, I am not sure how to do this. I suspect this involves
> writing a do file, which may or may not be a problem for me. The problem
> I have is that because I need a line to be fit (i.e. a beta 0
> (intercept) and a beta 1 (slope)) for each individual, I need to iterate
> a command for each observation, namely: regress v1 time if obs==x, where
> x is the observation number. How does iteration work in Stata? Is there
> a for loop equivalent?
>
> Bryan
>
> *
> * 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/
*
* 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/