From | "Michael Blasnik" <michael.blasnik@verizon.net> |
To | <statalist@hsphsun2.harvard.edu> |
Subject | st: Re: How to numerate different events from the same person? |
Date | Thu, 13 Oct 2005 11:01:35 -0400 |
I would like to assing to each discharge event of the same patient a number. The first discherge will be number 1, the second number 2 and so on.
This is the syntax I'm using. What's wrong with it? I don't know why local values remained unchange.
input patient diag
1 8151
1 8006
1 8153
2 8154
2 8155
3 8005
3 8155
end
gen lag_pat=patient[_n-1]
replace lag_pat=patient if lag_pat==.
gen ing=1
local j=1
local N=_N
forvalues i=1(1)`N'{
if (_n==`i' & patient==lag_pat) {
replace ing=`j'
local j=`j'+1
}
else local j=1
}
The result of this syntax was supposed to be:
+--------------------------------+
| patient diag lag_pat ing |
|--------------------------------|
1. | 1 8151 1 1 |
2. | 1 8006 1 2 |
3. | 1 8153 1 3 |
4. | 2 8154 1 1 |
5. | 2 8155 2 2 |
|--------------------------------|
6. | 3 8005 2 1 |
7. | 3 8155 3 2 |
+--------------------------------+
But I have obtained:
+--------------------------------+
| patient diag lag_pat ing |
|--------------------------------|
1. | 1 8151 1 1 |
2. | 1 8006 1 1 |
3. | 1 8153 1 1 |
4. | 2 8154 1 1 |
5. | 2 8155 2 1 |
|--------------------------------|
6. | 3 8005 2 1 |
7. | 3 8155 3 1 |
+--------------------------------+
Could anyboby help me?
Thanks a lot
Alejandro Allepuz Palau
* * 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/
© Copyright 1996–2025 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |