Dear Statalist,
I have a problem with a syntax I have used several times before. I'm trying to plot BMI values against HR using splines, and I'm using the user-written xblc command by Nicola Orsini. I'm using a new dataset, and this time my code doesn't produce the graph I'm used to. Here's the dataset, the code and the resulting graph. Can anyone spot the error?
BLF_fall_kontroll: 0=controls, 1=cases
enddate_bmi: end of follow-up
deceased....: date of death
BLF_unddat: date of origin
BMI: BMI
BLF_sex: 0=women, 1=men

I have a problem with a syntax I have used several times before. I'm trying to plot BMI values against HR using splines, and I'm using the user-written xblc command by Nicola Orsini. I'm using a new dataset, and this time my code doesn't produce the graph I'm used to. Here's the dataset, the code and the resulting graph. Can anyone spot the error?
BLF_fall_kontroll: 0=controls, 1=cases
enddate_bmi: end of follow-up
deceased....: date of death
BLF_unddat: date of origin
BMI: BMI
BLF_sex: 0=women, 1=men
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float id double BLF_fall_kontroll float enddate_bmi double(deceased_20160419 BLF_unddat BMI BLF_sex) 1 1 20020902 1 19970303 25.50361570247934 1 2 1 20763 0 19970311 22.77318640955005 0 3 1 20140408 1 19970311 25.55932915514163 1 4 1 20763 0 19970319 29.860551225775623 1 5 1 20763 0 19970414 20.957171162932475 0 6 1 20021230 1 19970417 38.805697589481376 0 7 1 20763 0 19970418 24.933720489837143 1 8 1 20763 0 19970421 21.71806608974573 1 9 1 20101012 1 19970421 22.481329065691202 0 10 1 20130410 1 19970421 19.77769866698311 0 11 1 20090528 1 19970429 26.91272587466359 0 12 1 20160224 1 19970502 25.5649539199596 1 13 1 20763 0 19970506 29.860551225775623 1 14 1 20140512 1 19970506 37.34186861758877 0 15 1 20763 0 19970513 26.89232313815483 0 16 1 20763 0 19970515 26.59279778393352 1 17 1 20763 0 19970528 23.38868655818771 1 18 1 20763 0 19980511 26.149276859504134 1 19 1 20763 0 19980511 25.082863029651524 1 20 1 20763 0 19980511 16.298185941043087 0 21 1 20030924 1 19980511 23.147255121330193 0 22 1 20120224 1 19980513 28.293345405160707 1 23 1 20763 0 19980603 27.993022029291247 0 24 1 20110612 1 19980603 25.390624999999996 0 25 1 20763 0 19980604 23.671253629592222 1 26 1 20120104 1 19980604 25.510204081632658 1 27 1 20101120 1 19980610 29.054752066115704 1 28 1 20763 0 19990923 20.549886621315196 0 29 1 20763 0 19991012 29.012345679012345 1 30 1 20763 0 19991012 25.781249999999996 1 31 1 20763 0 19991102 23.661438615467823 0 32 1 20763 0 19991108 20.281233098972418 0 33 1 20763 0 19991110 23.735308416025617 1 34 1 20763 0 19991112 26.775934114974238 0 35 1 20763 0 19991112 28.060018903591683 1 36 1 20763 0 19991123 24.221453287197235 0 37 1 20080208 1 19991209 20.904195011337873 0 38 1 20763 0 20000103 29.396221429515126 1 39 1 20763 0 20000124 30.863035868869737 1 40 1 20763 0 20000204 31.58861340679523 0 41 1 20031012 1 20000309 26.42356982428326 1 42 1 20050812 1 20000413 33.13975508142911 1 43 1 20763 0 20000530 19.227687870533565 0 44 1 20763 0 20000620 27.471707127713575 1 45 1 20111232 1 20000628 26.874496103198062 1 46 1 20763 0 20000629 23.56663223140496 1 47 1 20763 0 20010314 26.023048986244955 1 48 1 20763 0 20010403 26.82742078020452 1 49 1 20763 0 20010403 22.058051188683873 0 50 1 20763 0 20010405 28.554631729234906 1 51 1 20763 0 20010417 26.769779892920884 0 52 1 20763 0 20010419 20.077334919690664 0 53 1 20150228 1 20010419 21.79944510503369 1 54 1 20763 0 20010504 22.86236854138088 0 55 1 20763 0 20010508 22.34029706557179 1 56 1 20763 0 20010516 25.33500198406642 1 57 1 20763 0 20011024 28.73174689021093 0 58 1 20763 0 20011025 26.82742078020452 0 59 1 20763 0 20011031 26.672763298277697 0 60 1 20763 0 20011107 18.670934308794386 0 61 1 20763 0 20011113 25.4364666435426 1 62 1 20763 0 20011119 29.935443565181178 1 63 1 20763 0 20011213 22.95908765854944 0 64 1 20763 0 20020205 21.192742415229034 0 65 1 20763 0 20020206 21.296296296296294 1 66 1 20763 0 20020210 28.081632653061224 1 67 1 20763 0 20020305 23.661438615467823 0 68 1 20763 0 20020305 25.529644871208653 0 69 1 20763 0 20020306 22.052190183434128 1 70 1 20763 0 20020312 25.351541373715524 0 71 1 20763 0 20020313 26.014568158168572 1 72 1 20763 0 20020313 32.14024835646457 1 73 1 20763 0 20020527 23.66691015339664 1 74 1 20763 0 20020902 27.44059917355372 1 75 1 20763 0 20020902 38.505239237470015 1 76 1 20763 0 20020902 35.57941387597141 1 77 1 20763 0 20020902 24.307243558580453 1 78 1 20763 0 20020905 24.56747404844291 0 79 1 20763 0 20020905 30.86300682844026 0 80 1 20763 0 20020909 26.314635323012148 0 81 1 20763 0 20020909 25.21735857578381 0 82 1 20131014 1 20020909 25.10387811634349 0 83 1 20140408 1 20020909 24.111507464658473 1 84 1 20763 0 20020910 20.904195011337873 0 85 1 20763 0 20020910 24.755464315903875 1 86 1 20041112 1 20020910 20.04744562130375 0 87 1 20110122 1 20020910 22.944088878154812 1 88 1 20763 0 20020911 24.3046178773967 0 89 1 20050224 1 20020911 24.76756591982929 0 90 1 20051108 1 20020911 23.671253629592222 1 91 1 20070512 1 20020911 30.449826989619382 1 92 1 20763 0 20020912 27.74474831549742 1 93 1 20763 0 20020912 25.180785123966942 1 94 1 20070908 1 20020912 25.727555214006482 1 95 1 20150500 1 20020913 26.26494384736143 1 96 1 20763 0 20020916 24.76756591982929 0 97 1 20763 0 20020916 21.333333333333332 0 98 1 20140716 1 20020916 23.889462809917354 1 99 1 20763 0 20020917 24.96494647925858 1 100 1 20763 0 20020918 27.717685235262305 1 end format %td enddate_bmi label values BLF_fall_kontroll BLF_fall_kontroll label def BLF_fall_kontroll 1 "Fall (FEV1/(max av FVC och EVC)<0.7 pre-BD)", modify label values deceased_20160419 deceased_20160419 label def deceased_20160419 0 "Not deceased", modify label def deceased_20160419 1 "Deceased", modify label values BLF_sex BLF_sex label def BLF_sex 0 "Kvinna", modify label def BLF_sex 1 "Man", modify
Code:
gen id = _n replace BMI=round(BMI,.5) tabstat BMI, by(BLF_fall_kontroll) stat(n mean median min max p1 p99)
Code:
gen enddate_bmi = mdy(11,05,2016) format enddate_bmi %td label variable enddate_bmi "End of follow-up date" replace enddate_bmi = BLF_avlidendat_ratt if (deceased_20160419==1) browse BMI BLF_unddat enddate_bmi BLF_fall_kontroll in 1/100 foreach num of numlist 3/7{ preserve keep if BLF_fall_kontroll==0 stset enddate_bmi, id(id) failure(deceased_20160419==1) origin(time BLF_unddat) scale(365.25) mkspline spl_bmi = BMI, cubic nknots(`num') displayknots stcox c.spl_bmi* i.BLF_sex, vce(robust) estat ic levelsof BMI, local(levels) xblc spl_bmi*, covname(BMI) at(`levels') reference(26.3) eform gen(vbmi hr lb ub) keep if vbmi>16.0 & vbmi<48.5 twoway rline lb ub vbmi, lp(solid) lc(red) lw(medium) || line hr vbmi, lc(blue) lp(solid) lw(medium) /// legend(off) ylabel(, nogrid format(%3.2f)) yticks() xlabel(16(1)48, format(%3.0f)) xticks() xtitle("{bf:BMI(kg/m{sup:2})}") ytitle("{bf:HR (95% CI) for all-cause mortality}") /// yline(1, lc(black) lp(dash) lw(medthin)) name(no_copd_death_spl_bmi_knot`num', replace) saving("C:\.gph",replace) restore }