Announcement

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

  • Matching in Stata

    I have performed age-sex matched case-control study with 1:2 ratio. However, I have a problem facing with matching. I have performed the following but could not get the result
    se "D:\Academics\Research\Cardio metabolic risk factor\cardio-metabolic.dta", clear
    set seed 1234 // OR YOUR FAVORITE SEED

    // GENERATE AGE GROUPS (MODIFY LIMITS AS APPROPRIATE TO DATA)
    gen byte age_group = 1 if inrange(age, 18, 23)
    replace age_group = 2 if inrange(age, 24, 29)
    replace age_group = 3 if inrange(age, 30, 35)
    replace age_group = 4 if inrange(age, 36, 41)
    replace age_group = 5 if inrange(age, 42, 47)
    replace age_group = 6 if inrange(age, 48, 53)
    replace age_group = 7 if inrange(age, 54, 59)
    replace age_group = 8 if inrange(age, 60, 65)
    replace age_group = 9 if inrange(age, 66, 71)
    replace age_group = 10 if inrange(age, 72, 77)
    replace age_group = 11 if inrange(age, 77, .)


    gen double shuffle = runiform() // TO RANDOMIZE MATCH SELECTIONS

    // FORM A FILE OF CONTROLS ONLY
    preserve
    keep if case_control==0
    // ASSIGN A PRIORITY FOR MATCHING WITHIN EACH AGE_GROUP SEX COMBINATION
    // IN BATCHES OF (UP TO) FOUR
    rename gender sex
    by age_group sex (shuffle), sort: gen int priority = floor((_n-1)/2) + 1
    drop shuffle
    // RENAME VARIABLES TO AVOID CLASH
    rename * control_*
    foreach x in age_group sex priority {
    rename control_`x' `x'
    }
    tempfile controls
    save `controls'

    // NOW MAKE A FILE OF CASES
    restore
    keep if case_control==1
    // AGAIN PRIORITIZE FOR MATCHING
    rename gender sex
    by age_group sex (shuffle), sort: gen int priority = _n
    drop shuffle
    // MERGE WITH CONTROLS
    merge 1:m age_group sex priority using `controls', keep(master match)

  • #2
    You don't provide enough information to solve the problem. What does "I could not get the result" mean? Did Stata hang, or crash? Did it run but leave no output? Did it partially run and halt with an error message? (If so, what was the error message?) Did it run to completion with no error messages but the output looks wrong? (If so, in what way is it wrong?)

    In order for people to help, you need to answer those questions so they can tell what the problem is. In addition, you should provide example data, using the -dataex- command. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    I'm also confused by your first sentence, stating that you have already run the matched case-control analysis. If that is already done, why are you again running code to create matches?

    Comment


    • #3
      Thank you Clyde. I have collected data of 61 cases and 122 controls [i.e. 1:2]. I have written in the research report that it is age-sex matched. But I am not sure whether my data is age-sex matched or not. How can I know that the collected data is age-sex matched using Stata. In the meantime, by doing crosstab I found exactly the same ratio of cases and controls in terms of sex, but not found that age in exactly matched. I am lost somewhere.

      How can I prepare my dataset with one cases and two close controls using Stata? I have used the aforementioned code to do exercise but got lost. I want to see my dataset with columns age, sex with match_id having one case and two consecutive controls?

      Comment


      • #4
        I want to see my dataset with columns age, sex with match_id having one case and two consecutive controls?
        This is a bit like asking directions to a destination without disclosing where you are starting from. How to do it depends on how your data is organized, and just knowing that there are 61 cases and 122 controls isn't nearly enough information. You need to post example data, using the -dataex- command, to set this process in motion.

        Comment

        Working...
        X