Announcement

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

  • Case Matching 1:1 but for two different control groups based on insurance status

    Hello community,

    I am attempting to case match using Stata 15. I am using three waves of data (N=1,841; 2,366 variables) and am interested in how these three groups differed in health care use. I would like to match by age (age_5) and sex (sex).

    I desire to have three groups total: (1) group who transitioned onto Medicare at the middle time point (matchgroup==1); (2) those who always had Medicare (matchgroup==2); and (3) those who always had private insurance (matchgroup==3). I created these groups using the following syntax:

    generate matchgroups=.
    replace matchgroups=1 if [ins1_5==0] & [ins1_6==1] & [ins1_7==1]
    replace matchgroups=2 if [ins1_5==1] & [ins1_6==1] & [ins1_7==1] & [ins2_5==0] & [ins2_6==0] & [ins2_7==0] & [ins8_5==0] & [ins8_6==0] & [ins8_7==0] & [ins3_5==0] & [ins3_6==0] & [ins3_7==0] & [ins9_5==0] & [ins9_6==0] & [ins9_7==0] & [ins5_5==0] & [ins5_6==0] & [ins5_7==0] & [ins6_5==0] & [ins6_6==0] & [ins6_7==0]
    replace matchgroups=3 if [ins1_5==0] & [ins1_6==0] & [ins1_7==0] & [ins2_5==0] & [ins2_6==0] & [ins2_7==0] & [ins8_5==0] & [ins8_6==0] & [ins8_7==0] & [ins3_5==0] & [ins3_6==0] & [ins3_7==0] & [ins9_5==0] & [ins9_6==0] & [ins9_7==0] & [ins5_5==1] & [ins5_6==1] & [ins5_7==1] & [ins6_5==0] & [ins6_6==0] & [ins6_7==0]
    Using Tab:
    Matchgroup==1 = (n=67)
    Matchgroup==2 = (n=128)
    Matchgroup==3 = (n=268)

    After installing rangejoin (ssc install rangejoin), I attempted to use syntax from a previous thread (https://www.statalist.org/forums/for...age-and-gender) and have received the following error terms:

    . // SEPARATE CASES FROM CONTROLS
    . // AND DISTINGUISH VARIABLE NAMES
    . preserve
    . keep if matchgroup == 1
    (1,774 observations deleted)
    . tempfile controls
    . save `controls'
    file C:\Users\JLAURE~1\AppData\Local\Temp\ST_cb0_000002 .tmp saved
    . restore
    . keep if matchgroup==2
    (1,713 observations deleted)
    . rangejoin age_5 -10 10 using 'controls', by(sex)
    invalid 'controls'
    r(198);
    end of do-file
    r(198);
    . do "C:\Users\JLAURE~1\AppData\Local\Temp\STDcb0_0 0000 0.tmp"
    . rangejoin age_5 -10 10 using `controls', by(sex)
    invalid file specification
    r(198);

    **I am also open to using other ways to match. I have seen commands such as: psmatch, ccmatch, joinby/rangejoin. But, was unsure how to use them when i need to pull one control from two groups.

    Please advise, thank you for your time.
    Last edited by Jenn Wong; 11 Jun 2018, 16:15. Reason: Additional information regarding open to using other syntax commands

  • #2
    I was about to point out that you incorrectly use square brackets instead of parentheses when you define the matchgroups variable but I checked and surprisingly, square brackets can be used interchangeably with parentheses in expressions as long as they are balanced:
    Code:
    sysuse auto, clear
    gen test1 = 1 if [turn==40] & [mpg==24]
    gen test2 = 1 if (turn==40) & [mpg==24]
    gen test3 = 1 if (turn==40) & (mpg==24)
    assert test1 == test3
    And it's not just that square brackets are being ignored, they can be used to change the order of evaluation:
    Code:
    gen test4 = [mpg + turn] * rep78
    gen test5 = (mpg + turn) * rep78
    assert test4 == test5
    I don't know if there's some history about this but this certainly does not conform to the current description of the Stata language where square brackets are used to define weights and with explicit subscripting (and a few other cases). Please use parentheses in expressions when your intention is to control the order of operations.

    As to the errors you are getting, I suspect that you are running the code in parts within the editor by selecting lines and clicking on the Do button. The code is meant to be run as a whole. When you run it in parts, locals defined within the code chunk disappear when the chunk terminates and therefore are not found when you try to run the next code chunk.

    Comment


    • #3
      Hi Robert,

      I will certainly use parentheses in the future as to not complicate things. I appreciate your clarification on why they are to be used in an effort to not change the order of evaluation. I have edited my syntax to reflect your recomendations.

      I am still running into errors regarding matching, even when running it together. Perhaps I should eliminate the code I was working with and ask for help with matching.




      I have three groups: Group 1 (n=67), Group 2 (n=128), and Group 3 (n=268).

      Group 1 is my group of interest and I would like to find matching samples from groups 2 and 3 on age and sex. Is there code you would recommend?

      Thank you in advance!

      Comment

      Working...
      X