BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Emily_Chi
Fluorite | Level 6

I am currently analyzing the impact of an intervention on medication numbers using difference-in-difference analysis, but I have encountered several problems.

 

Following the SAS support instructions, I conducted the difference-in-difference analysis. However, I noticed a discrepancy between my results and SAS's example 61830.

 

In the example, the value of 'Mean Estimate' in 'Contrast Estimate Results' is identical to the 'Estimate' in 'Least Squares Means Estimate'. However, in my case, these values were different. I suspect this could be due to my use of the negative binomial distribution with a log link, resulting in exponential values. Consequently, I am unsure whether to rely on the 'Mean Estimate' in 'Contrast Estimate Results' or the 'Estimate' in 'Least Squares Means Estimate', and how to interpret this results.

Thank you very much.

 

 

Here is my result:

 

Contrast Estimate Results

LabelMean Estimate

Mean Confidence Limits

L'Beta EstimateStandard
Error
Pr > ChiSq
diff in diff1.51

1.49-1.52

0.410.0051

<.0001

 

time*intervention  Least Squares Means

timeinterventionEstimateSEz valuePr > |z|
110.770.00434178.19<.0001
100.030.005086.5<.0001
010.720.00408177.71<.0001
000.400.0042693.11<.0001

 

Least Squares Means Estimate

EffectLabelEstimateSEZ valuePr > |z|
time*intervention diff in diff0.410.0050981.01<.0001

 

 

SAS code:

 

 

proc genmod data = ALL_DID;
    class _MatchID intervention time /ref = first;
    model drug_use = time intervention time*intervention/dist = negbin link=log;
	repeated subject =_MatchID/type = exch;
    estimate "diff in diff" time*intervention 1 -1 -1 1;
	lsmeans time*intervention;
	lsmestimate time*intervention "diff in diff" 1 -1 -1 1;
run;

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
dpalmer1
Fluorite | Level 6

You're correct about the numbers differing due to the log link function with the negative binomial GEE.  Exponentiating "L'Beta" in the "Contrast Estimate Results" table will give you the "Mean Estimate" result back on the original scale.

data _null_;
	estimate = 0.41;
	expEstimate = exp(estimate);
	put estimate = expEstimate = ;
run;

This is achieved by adding the "exp" option to your estimate statement.  Exponentiating the estimates in the "time*intervention Least Squares Means" table will give you the "Mean" results back on the original scale.

data _null_;
	input lsmeans;
	expLSMeans = exp(lsmeans);
	put lsmeans = expLSMeans = ;
	datalines;
	0.77
	0.03
	0.72
	0.40
;

This is achieved by adding the "ilink" option to your lsmeans statement.  Exponentiating the estimate in the "Least Squares Means Estimate" table will give you the "Mean" result back on the original scale. This is achieved by adding the "ilink" option to your lsestimate statement.  Additionally, you can obtain the chi-square statistic in the "Contrast Estimate Results" table by squaring the Z statistic in the "Least Squares Means Estimate" table.

data _null_;
	estimate = 0.41;
	expEstimate = exp(estimate);
	Z = 81.01;
	ChiSq = Z ** 2;
	put estimate = expEstimate = Z = ChiSq = ;
run;

 

View solution in original post

2 REPLIES 2
dpalmer1
Fluorite | Level 6

You're correct about the numbers differing due to the log link function with the negative binomial GEE.  Exponentiating "L'Beta" in the "Contrast Estimate Results" table will give you the "Mean Estimate" result back on the original scale.

data _null_;
	estimate = 0.41;
	expEstimate = exp(estimate);
	put estimate = expEstimate = ;
run;

This is achieved by adding the "exp" option to your estimate statement.  Exponentiating the estimates in the "time*intervention Least Squares Means" table will give you the "Mean" results back on the original scale.

data _null_;
	input lsmeans;
	expLSMeans = exp(lsmeans);
	put lsmeans = expLSMeans = ;
	datalines;
	0.77
	0.03
	0.72
	0.40
;

This is achieved by adding the "ilink" option to your lsmeans statement.  Exponentiating the estimate in the "Least Squares Means Estimate" table will give you the "Mean" result back on the original scale. This is achieved by adding the "ilink" option to your lsestimate statement.  Additionally, you can obtain the chi-square statistic in the "Contrast Estimate Results" table by squaring the Z statistic in the "Least Squares Means Estimate" table.

data _null_;
	estimate = 0.41;
	expEstimate = exp(estimate);
	Z = 81.01;
	ChiSq = Z ** 2;
	put estimate = expEstimate = Z = ChiSq = ;
run;

 

Emily_Chi
Fluorite | Level 6

@dpalmer1 Thank you so much! Your assistance means a lot to me.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 737 views
  • 3 likes
  • 2 in conversation