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.
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.
Comment