28
Stata Technical Bulletin
STB-22
Now, after creating dummies for the time period ...
. tabulate period, generate(per)
Time period I |
Freq. |
Percent |
Cum. |
-SO I |
14 |
42.42 |
— 42.42 |
[80-90 I |
11 |
33.33 |
75.76 |
[90- I |
8 |
24.24 |
100.00 |
Total I |
33 |
100.00 |
— |
and a censoring variable ...
. censor id age = activity==l ∣ activity==2, generate(jobi)
we can estimate a Cox regression model:
. cox Tjobl per2 per3, tvid(id) dead(jobl)
We suppress the output of cox because our example data are too artificial to make the results meaningful. We have, however,
illustrated the process of preparing data for Cox regression; you can apply it to authentic data of your own.
Combining files by time
tmerge is a utility to combine two files each containing ordered observations on one or more individuals. The syntax of
tmerge is
tmerge ident~var filenameA(time.varA) filenameB (time-varlT) new filename (new Jime _var)
tmerge combines filenameA and filenameB and stores the result in new filename (and in the current data set). Observations are
matched according to the values of time-varA and time-varB, which must be expressed in the same scale.
As with the commands described above, tmerge is best understood by looking at an example. Suppose you have two files
containing different event histories for the same individual. One file, job.dta, contains the individual’s employment history:
. use job, clear
. list
id |
birth |
Tjob |
prof | |
1. |
2 |
63 |
80 |
3 |
2. |
2 |
63 |
84 |
1 |
3. |
2 |
63 |
85 |
2 |
4. |
2 |
63 |
89 |
1 |
The other file, mar.dta, contains the individual’s marriage history:
. use mar, clear
. list
id |
birth |
carl |
Tmar |
car2 | |
1. |
2 |
63 |
1 |
78 |
4 |
2. |
2 |
63 |
2 |
89 |
3 |
Time variables—Tjob in job.dta, Tmar in mar.dta—must be expressed in the same scale (here, in years). In each file the
censoring time is 89. tmerge will be interrupted and an error message will appear if the times at censoring are not the same in
both files. To combine the files, type
. drop _all
. tmerge id job(Tjob) mar(Tmar) job-mar(time)
set maxvar 19 width 29
Please wait...