Dear Stata-users,
Below is a segment I have of a child's record that includes 22 visits:
+---------------------------------------------------------------+
| visit sex age tage weight tweight thresh flag |
|---------------------------------------------------------------|
| 19 2 549 548 12.1 12.1 7 0 |
| 20 2 583 609 12.35 . 7 1 |
| 21 2 670 670 13.85 13.85 7 0 |
+---------------------------------------------------------------+
I need your help to structure a STATA code that would perform a linear fit within a child's record as follows:
By child:
take the observed weight when flag==1, the weight[_n-1] and weight[_n+1];
regress the 3 points weights on the 3 points age (age[_n], age[_n-1], age[_n+1])
and return the beta-coefficient of that model
or
predict tweight for tage(=609) if flag==1 using that model
Many thanks for your help in advance.
All the best,
Amani
<<winmail.dat>>