Hi. My data set spans July 2020- July 2024. There are two indicator variables for two treatments - one starting in July 2023 and the other in Jan 2024. Once both the treatments start, they run till the end of the study period (July 2024). The scatterplot below indicates the distribution for observations (variable in data is "one") during this period. I want to shade differently the different periods of time: non-intervention period (July 2020 - July 2023) - white, first intervention period (July 2023 - Jan 2024) - light grey, second intervention period (Jan 2024 - July 2024/end of study) - dark grey.
In addition, I would also like the line of fit to be solid in the pre-intervention period and dashed after the start of the first intervention.
Any help in doing this will be much appreciated.
In addition, I would also like the line of fit to be solid in the pre-intervention period and dashed after the start of the first intervention.
Any help in doing this will be much appreciated.
Code:
*Code gen mdate = ym(year, month) set scheme s1color su year, meanonly local first = r(min) local last = r(max) forval y = `first'/`last' { su mdate if year == `y', meanonly local labelcall `labelcall' `r(mean)' "`y'" local tickpos = r(max) + 0.5 if `y' < `last' local tickcall `tickcall' `tickpos' } mac li scatter one mdate, /// ytitle("Number of teleconsults") yscale(range(0 .)) ylabel(#6, labsize(small) /// angle(horizontal) nogrid) ms(Oh) mc(black) /// xtick(`tickcall', tlength(*2)) /// xla(`labelcall', noticks labsize(small)) /// xtitle("Year" "", height(6)) graphregion(fcolor(white)) || lfit one mdate, legend(off) xli(`tickcall', lc(gs12)) *Data Sample input float(year month) long one byte(treatment1 treatment2) 2020 7 1585 0 0 2020 8 2460 0 0 2020 9 2778 0 0 2020 10 3284 0 0 2020 11 3280 0 0 2020 12 3262 0 0 2021 1 2688 0 0 2021 2 2849 0 0 2021 3 2806 0 0 2021 4 2517 0 0 2021 5 4012 0 0 2021 6 2665 0 0 2021 7 2556 0 0 2021 8 2618 0 0 2021 9 2693 0 0 2021 10 2247 0 0 2021 11 2028 0 0 2021 12 2217 0 0 2022 1 2233 0 0 2022 2 2224 0 0 2022 3 2326 0 0 2022 4 2052 0 0 2022 5 2059 0 0 2022 6 1656 0 0 2022 7 1574 0 0 2022 8 1386 0 0 2022 9 1361 0 0 2022 10 1071 0 0 2022 11 1154 0 0 2022 12 1109 0 0 2023 1 1076 0 0 2023 2 1264 0 0 2023 3 1174 0 0 2023 4 906 0 0 2023 5 968 0 0 2023 6 1012 1 0 2023 7 1097 1 0 2023 8 1517 1 0 2023 9 1248 1 0 2023 10 1098 1 0 2023 11 975 1 0 2023 12 1000 1 0 2024 1 1112 1 1 2024 2 1060 1 1 2024 3 945 1 1 2024 4 1017 1 1 2024 5 916 1 1 2024 6 1120 1 1 2024 7 1174 1 1
Comment