Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • match age and gender

    Hello, I would like to know how to match 2:1 for age and gender using same sample of individuals. I have 1007 individuals and have variables id, sex, age. I looked up 2 different examples in the forum, but the examples use two different populations. I would like to match using same sample of individuals. thanks in advance.

  • #2
    It sounds as if you want a stratified 2;1 randomization. I'm sure that there are at least a couple of user-written commands for that, and you could try the search command for them. You can also do it from scratch yourself using something like that below.
    Code:
    version 15.1
    
    clear *
    
    set seed `=strreverse("1496172")'
    quietly set obs 1007
    
    generate byte sex = mod(_n, 2)
    label define Sexes 0 F 1 M
    label values sex Sexes
    
    generate byte age = runiformint(18, 88)
    
    generate str pid = string(_n, "%04.0f")
    
    *
    * Begin here
    *
    egen long stratum = group(sex age)
    
    generate double randu = runiform()
    isid randu
    
    /* Begin removing incomplete strata */
    bysort stratum (randu): generate int obs = _n // Randomization occurs here
    
    generate byte triple = 1
    summarize obs, meanonly
    forvalues obs = 3(3)`r(max)' {
        quietly replace triple = triple + 1 if obs > `obs'
    }
    
    quietly bysort stratum triple (randu): drop if _N < 3
    /* End removing incomplete strata */
    
    by stratum triple: generate byte grp = mod(_n, 3) == 0
    label define Groups 0 Control 1 Experimental
    label values grp Groups
    // Done
    
    list pid sex age grp in 1/6, noobs sepby(triple) // 2:1 matching within strata
    
    list pid sex age grp in -6/l, noobs sepby(triple)
    
    tabulate grp // 2:1 matching overall
    
    exit

    Comment

    Working...
    X