// Turn date from string to Stata format gen date2 = date(date, "DMY") format date2 %td // Create local that contains the most recent date for labeling lines directly qui sum date2 local lastdate = r(max) // Create list of groups local groups A B C D // Create value of outcome for each group foreach x of local groups { qui sum outcome if group == "`x'" local `x'_count = r(max) + (log(r(max)) * 10) // This is to offset the label a bit } // Figure twoway (connected outcome date2 if groups == "A", msymbol(x)) /// (connected outcome date2 if groups == "B", msymbol(x)) /// (connected outcome date2 if groups == "C", lcolor(red) mcolor(red) msymbol(x)) /// (connected outcome date2 if groups == "D", msymbol(x)) /// (scatteri `A_count' `lastdate' (9) "{it:A}" /// `B_count' `lastdate' (9) "{it:B}" /// `C_count' `lastdate' (9) "{it:C}" /// `D_count' `lastdate' (9) "{it:D}" /// , msymbol(i)) /// , ytitle("Outcome") ylabel(, format(%9.0gc)) /// xtitle("") xlabel(,ang(30) format(%tdMonth_dd)) /// // This is to format the date legend(off) name(figure, replace)
