BookmarkSubscribeRSS Feed
sasgorilla
Pyrite | Level 9

I have a dataset with an interruption and a control and intervention group, and observed monthly outcomes pre- and post-interruption over a few year period (i.e. CITS design). 

I have used proc arima to generate estimates for interruption level and trend changes based on exposure status. 

As far as graphically depicting this, I am wondering the best approach to make something like the below (source), where i have pre- and post-interruption trends and level changes clearly depicted PLUS the "counterfactual" had the intervention not occurred.

 

sasgorilla_0-1752125074243.png

If any one has some suggestions I would appreciate it. Thank you. 



2 REPLIES 2
Rick_SAS
SAS Super FREQ

You didn't supply data, so I simulated some data to illustrate. I only used one group, but you can add GROUP=factor to each BAND/SERIES/SCATTER statement to get separate lines/points for factor=0 and factor=1.  You can ignore the DATA step and just focus on the PROC SGPLOT statements.

 

/* Simulate data that looks like the OP's picture */
data Sim;
call streaminit(12);
sigma = 5;
offset = 100;
do t = 1 to 100;
   factor = 0;
   if t <= 50 then do;
      c = 0;
      m = -1;
   end;
   else do;
      c = -50;
      m = -1.5;
   end;
   pred = 300 + m*t + c;
   lclm = pred - sigma;
   uclm = pred + sigma;
   y = pred + rand("Normal", 0, sigma);
   counter_pred = 300 - t;
   counter_lclm = counter_pred - sigma;
   counter_uclm = counter_pred + sigma;
   output;
end;
run;

title "Time Series Model with Interruption";
proc sgplot data=Sim;
  /* plot counterfactual in background */
  band x=t lower=counter_lclm upper=counter_uclm / transparency=0.5;
  series x=t y=counter_pred / lineattrs=(pattern=dash);
  /* then overlay the predictions */
  band x=t lower=lclm upper=uclm;
  series x=t y=pred;
  /* then plot the data */
  scatter x=t y=y;
  xaxis grid;
  yaxis grid;
run;
sasgorilla
Pyrite | Level 9

Sorry for the slow reply, @Rick_SAS ! Thank you for this. I will give it a whirl.