Warm tip: This article is reproduced from serverfault.com, please click

Stata: How can I generate a dataset from the results of a case-control study?

发布于 2020-12-01 15:12:45

I have the following results that I'd like to put into Stata and run some analysis:

Case control data

Is there a way I can generate the dataset for this data in Stata so that there are the appropriate number of observations, allowing me to run tabodds or similar?

Questioner
catalina
Viewed
0
Wouter 2020-12-02 00:04:09

Perhaps this is what you are looking for.

clear
set obs 6
gen region = word("`c(ALPHA)'", ceil(_n / 2))
bysort region : gen control = _n - 1
label define casecontrol 1 "Control" 0 "Case"
label values control casecontrol
local expandlist 708 1392 946 2086 328 996
gen exp = real(word("`expandlist'", _n))
expand exp
drop exp
tab region control

Result:

. tab region control

           |        control
    region |      Case    Control |     Total
-----------+----------------------+----------
         A |       708      1,392 |     2,100 
         B |       946      2,086 |     3,032 
         C |       328        996 |     1,324 
-----------+----------------------+----------
     Total |     1,982      4,474 |     6,456