Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

statistics - how can I create a loop for risk-set sampling

I need to select 10 controls per case for my case-control study. Controls are matched only on index date (risk-set sampling). I am working on a very large dataset so I created the following to demonstrate my variables.

I copied them using dataex in Stata:

* Example generated by -dataex-. To install: ssc install dataex
clear
input byte patid float pracid int index float(event dateofbirth transferout)
10 3  9132 1 -1826  9141
11 3     . 0  9497 18263
12 3     . 0 12815 17532
20 7     . 0  2192     .
21 3     . 0 -2191 10958
23 3     . 0  8766 20089
32 3     . 0  5114  8766
33 3     . 0 11323     .
34 7     . 0 20089     .
37 7     . 0 20089     .
40 7     . 0 -3652 12784
42 7     . 0  2234 16835
43 7     . 0  7305 16802
44 3     . 0  2922  7305
55 7     . 0  4383 15007
58 7     . 0 10958 16437
60 3     . 0 16562 21549
61 7 14610 1 -3652 14641
65 3     . 0  7305  8401
70 7     . 0  9334 21976
75 3     . 0  6210     .
76 7     . 0  6575 16437
77 7     . 0 -7305     .
78 3     . 0  1827 14610
83 3     . 0 -7214 18263
87 3     . 0  3653 16437
88 7     . 0 15765 16922
90 7     . 0 15706 18263
93 7     . 0 -1645 18628
98 7     . 0  5479 21550
99 3 16437 1  2922 16496
end
format %tdDD/NN/CCYY index
format %d dateofbirth
format %d transferout
label values event death
label def death 0 "no death", modify
label def death 1 "death", modify

To select controls, I am wondering how can I create a loop that says for each case,

  1. eliminate all participants who are cases too who passed away before the index date.

  2. then from the remaining participants, randomly select 10 who fulfill eligibility criteria. Eligibility criteria include age 15 years and above AT index date and transfer out date AFTER index date.

  3. put for these participants (the case and 10 controls) a matched pair ID.

NB- the -sttocc- command was useless in my situation.

Your help is much appreciated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...