import excel using "repeated measured data.xlsx", firstrow clear
keep if pid==433
local daystoope = opedate - b_date
local daystoicu1 = icudate1 - b_date
twoway connected egfr daysfrombl, ///
xtitle("最初のeGFR測定からの経過日数(日)") ///
xline(`daystoope' , lw(vthick) lcolor(green%50)) ///
xline(`daystoicu1', lw(vthick) lcolor(yellow%50)) ///
ytitle("eGFR") yscale(range(0 60)) ylabel(0(20)60)
これで、入院中の採血ポイントの色を変えたい場合には、散布図を同じtwowayグラフに重ねます.
import excel using "repeated measured data.xlsx", firstrow clear
keep if pid==433
local daystoope = opedate - b_date
local daystoicu1 = icudate1 - b_date
twoway (connected egfr daysfrombl) ///
(scatter egfr daysfrombl if 入外=="入院", mcolor(maroon)), ///
xtitle("最初のeGFR測定からの経過日数(日)") ///
xline(`daystoope' , lw(vthick) lcolor(green%50)) ///
xline(`daystoicu1', lw(vthick) lcolor(yellow%50)) ///
ytitle("eGFR") yscale(range(0 60)) ylabel(0(20)60) ///
legend(order(1 "外来検査" 2 "入院中検査"))
global wd "C:\Users\...(自分の指定するDirectory)...\"
import excel using "repeated measured data.xlsx", firstrow clear
label define yesno 1 "Yes" 0 "No"
label values chf yesno
label values cancer yesno
label values dm yesno
levelsof pid, local(levels)
foreach v of local levels {
preserve
keep if pid ==`v'
local x = dm
local dm "`: label (dm) `x''"
local y = chf
local chf "`: label (chf) `y''"
local z = cancer
local cancer "`: label (cancer) `z''"
local daystoope = opedate - b_date
local daystoicu1 = icudate1 - b_date
#delimit
twoway (connected egfr daysfrombl )
(scatter egfr daysfrombl if 入外=="入院", mcolor(maroon))
xtitle("最初のeGFR測定からの経過日数(日)") xline(365 730, lw(vthin) lcolor(black) lp(dash))
xline(`daystoope' , lw(vthick) lcolor(green%50))
xline(`daystoicu1', lw(vthick) lcolor(yellow%50))
ytitle("eGFR") yscale(range(0 60)) ylabel(0(20)60)
yscale(range(0(30)90)) ylabel(0(30)90, ang(0) nogrid) graphregion(color(white))
legend(order(1 "外来検査" 2 "入院中検査")) text(90 50 "PID: `v'" "DM: `dm'" "CHF: `chf'" "Cancer: `cancer'")
#delimit cr
graph export "${wd}figure/`v'.png", as(png) name("Graph") replace
restore