Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • No output when trying to plot spline curves

    Dear Statalist,

    I want to plot a spline curve of free fat mass (FFM) towards HRs from a Cox regression. I use the dataset and the code below. I have used a similar code before with other variables than FFM, and it has worked as it should. However, this time I am getting a strange output (copy-pasted below), with only missing values in the expression, and a resulting graph without anything else than a coordinate system. I have tried a workaround using
    Code:
    replace Ffm_NT4BLM=round(Ffm_NT4BLM,.5)
    without any luck. Could anyone help me?


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(id enddate_bmi) double RegisStat long PartDat_NT4LuM double Ffm_NT4BLM
      1 22006 1     .    .
      2 22006 1     .    .
      3 22006 1     .   45
      4 22006 1     .    .
      5 22006 1     . 76.5
      6 22006 1 21214   66
      7 22006 1 21145 41.5
      8 17667 5     .    .
      9 22006 1     .   48
     10 16694 3     .    .
     11 21350 5     .    .
     12 22006 1     . 45.5
     13 22203 5     . 59.5
     14 22006 1     .    .
     15 16237 5     .    .
     16 22006 1     .    .
     17 16847 5     .    .
     18 22006 1     .    .
     19 22006 1     .   73
     20 22006 1     .    .
     21 22006 1     . 62.5
     22 22006 1     . 61.5
     23 22006 1     .    .
     24 22006 1     .    .
     25 15628 5     .    .
     26 22006 1     .   44
     27 13984 5     .    .
     28 22006 1     .    .
     29 20499 5     .    .
     30 22006 1 21095 48.5
     31 22006 1     . 58.5
     32 22006 1     .    .
     33 22006 1     . 37.5
     34 22006 1     .    .
     35 22006 1     .    .
     36 22006 1     .    .
     37 22006 1     . 48.5
     38 13710 5     .    .
     39 22006 1     .    .
     40 22006 1     .   35
     41 16420 5     .    .
     42 22006 1     .   66
     43 22006 1 21353 50.5
     44 22006 1 21087   67
     45 22006 1     .   55
     46 22006 1     .    .
     47 22006 1     .   65
     48 22006 1     .    .
     49 22006 1     .    .
     50 22006 1     . 44.5
     51 22006 1     . 42.5
     52 15294 5     .    .
     53 22006 1     .    .
     54 22006 1     .    .
     55 22006 1 21432 37.5
     56 22006 1     .   68
     57 22006 1     .    .
     58 22006 1     . 51.5
     59 22006 1 21440   45
     60 22006 1     . 43.5
     61 21776 5     .    .
     62 16724 5     .    .
     63 22006 1     . 39.5
     64 22006 1     . 64.5
     65 21046 5     .    .
     66 22006 1     .    .
     67 22006 1     .   45
     68 22006 1     .    .
     69 14715 5     .    .
     70 18246 3     .    .
     71 22006 1     .   37
     72 22006 1     .    .
     73 22006 1     . 41.5
     74 22006 1 21819   44
     75 22006 1     .    .
     76 22006 1     .    .
     77 17212 5     .    .
     78 22006 1     .    .
     79 22006 1     . 56.5
     80 22006 1 21111 79.5
     81 22006 1 21080 44.5
     82 22111 5     .   58
     83 22006 1 21800   71
     84 17577 5     .    .
     85 22006 1     .    .
     86 17943 5     .    .
     87 22006 1     .    .
     88 22006 1     .    .
     89 16875 5     .    .
     90 21929 5     .    .
     91 22006 1     .    .
     92 22203 5     .   45
     93 22006 1     .   51
     94 22006 1     .    .
     95 22006 1     .    .
     96 18550 5     .    .
     97 22006 1 21265   48
     98 22006 1     .    .
     99 22006 1     . 54.5
    100 22006 1     . 37.5
    end
    format %td enddate_bmi
    format %tdD_m_Y PartDat_NT4LuM
    label values RegisStat RegisStat
    label def RegisStat 1 "Bosatt", modify
    label def RegisStat 3 "Utvandret", modify
    label def RegisStat 5 "Død", modify

    Code:
    foreach num of numlist 3/7{
            preserve        
            stset enddate_bmi, id(PID_109925) failure(RegisStat==5) origin(time PartDat_NT4LuM) scale(365.25)
            mkspline spl_ffm = Ffm_NT4BLM, cubic nknots(`num') displayknots            
            stcox c.spl_ffm* i.Sex, vce(robust)
            estat ic
            levelsof Ffm_NT4BLM, local(levels)
            xblc spl_ffm*, covname(Ffm_NT4BLM) at(`levels') reference(54.8) eform gen(wbmi hr lb ub)
            keep if wbmi>26.0 & wbmi<118.0
            twoway rline lb ub wbmi, lp(solid) lc(red) lw(medium) || line hr wbmi, lc(blue) lp(solid) lw(medium) ///
            legend(off) ylabel(, nogrid format(%3.2f)) yticks() xlabel(26(1)118, 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_ffm_knot`num', replace) saving("C:\.gph",             replace)
            restore
    }
    Parts of output:

    Code:
    Ffm_NT4BLM    exp(xb)    (95% CI)
    26.5            .        (  .-  .)
    27              .        (  .-  .)
    27.5            .        (  .-  .)
    28              .        (  .-  .)
    28.5            .        (  .-  .)
    29              .        (  .-  .)
    29.5            .        (  .-  .)
    30              .        (  .-  .)
    30.5            .        (  .-  .)
    31              .        (  .-  .)
    31.5            .        (  .-  .)
    32              .        (  .-  .)
    32.5            .        (  .-  .)
    33              .        (  .-  .)
    33.5            .        (  .-  .)
    34              .        (  .-  .)
    34.5            .        (  .-  .)
    35              .        (  .-  .)
    35.5            .        (  .-  .)
    36              .        (  .-  .)
    36.5            .        (  .-  .)
    37              .        (  .-  .)
    37.5            .        (  .-  .)

  • #2
    I fixed the error: I needed to round the mean of the dependent variable up to the nearest integer.

    Comment

    Working...
    X