Announcement

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

  • Error code "r(123); invalid numlist has too many elements"

    Dear Statalist,

    I'm running this code, generating cubic splines for the variable FFMI against HRs. This gives me the error code "r(123); invalid numlist has too many elements". Why does this happen, and how can I improve my code to avoid this?


    Code:
    foreach num of numlist 3/7{
            preserve
            keep if cohort==1 & PartAg_NT4BLQ1>40.0 & PartAg_NT4BLQ1!=.    
            stset enddate_ffmi, id(PID_109925) failure(RegisStat==5) origin(time BirthYear) enter(time PartDat_NT4BLQ1) scale(365.25)
            mkspline spl_ffmi = FFMI, cubic nknots(`num') displayknots            
            stcox c.spl_ffmi* i.Sex, vce(robust)
            estat ic
            levelsof FFMI, local(levels)
            xblc spl_ffmi*, covname(FFMI) at(`levels') reference(18.5) eform gen(wffmi hr lb ub)
            keep if wffmi>12.0 & wffmi<29.0
            twoway rline lb ub wffmi, lp(solid) lc(red) lw(medium) || line hr wffmi, lc(blue) lp(solid) lw(medium) ///
            legend(off) ylabel(, nogrid format(%3.2f)) yscale(log) yticks() xlabel(12(1)29, format(%3.0f)) xticks() xtitle("{bf:FFM     (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_ffmi_knot`num', replace) saving("M:\FFMIsplines.gph",             replace)
            restore
    }
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str13 PID_109925 float FFMI
    "1099250000068" 20.257673
    "1099250000075"  16.41549
    "1099250000303" 16.261368
    "1099250000433" 18.844908
    "1099250000440" 19.078123
    "1099250000556" 16.711199
    "1099250000594" 16.096815
    "1099250000747" 17.166037
    "1099250000808"  23.12851
    "1099250000815" 16.872831
    "1099250000839"  21.20099
    "1099250000976" 18.357824
    "1099250001072" 15.002635
    "1099250001102" 16.622509
    "1099250001218"  15.96405
    "1099250001379" 17.252134
    "1099250001645" 18.876345
    "1099250001690" 16.994984
    "1099250001874"  20.27285
    "1099250001911"  24.86499
    "1099250001980" 15.426138
    "1099250001997"  20.51911
    "1099250002000" 21.389755
    "1099250002017" 18.948357
    "1099250002031" 20.587954
    "1099250002079" 16.991798
    "1099250002086"  22.66436
    "1099250002154" 17.340462
    "1099250002185" 21.074715
    "1099250002222"  14.76981
    "1099250002307"  20.29168
    "1099250002499"  20.79452
    "1099250002604" 15.637706
    "1099250002680" 13.729548
    "1099250002727" 24.500887
    "1099250002840" 17.770155
    "1099250002956" 17.600523
    "1099250002970" 16.451637
    "1099250003007"  22.63712
    "1099250003052" 19.406385
    "1099250003144" 16.657373
    "1099250003243"  20.07525
    "1099250003366" 17.922968
    "1099250003373" 18.827162
    "1099250003618"  16.72992
    "1099250003700" 15.712954
    "1099250003731" 18.618073
    "1099250003984" 16.122509
    "1099250004004" 22.994595
    "1099250004035" 19.515856
    "1099250004042" 14.438632
    "1099250004073" 17.067698
    "1099250004103" 17.162767
    "1099250004134" 20.198105
    "1099250004141"  21.98878
    "1099250004196" 20.644033
    "1099250004219"  19.55816
    "1099250004233" 19.101213
    "1099250004295"  19.83154
    "1099250004486" 14.690882
    "1099250004516" 16.955017
    "1099250004615" 19.148285
    "1099250004752"  19.73008
    "1099250004783" 17.988977
    "1099250004868" 16.573256
    "1099250004899" 17.834265
    "1099250004998" 17.433004
    "1099250005025"  20.97489
    "1099250005049" 18.173464
    "1099250005216"  21.99749
    "1099250005278"  19.14934
    "1099250005285" 16.772224
    "1099250005360"  15.84676
    "1099250005421"  22.20912
    "1099250005445" 15.887088
    "1099250005544" 17.749592
    "1099250005681" 17.077469
    "1099250005728"   21.3407
    "1099250005797" 16.324526
    "1099250005803"  19.90521
    "1099250005834" 20.154686
    "1099250005865" 16.670069
    "1099250005988"  20.57978
    "1099250006190" 17.966629
    "1099250006213" 24.858364
    "1099250006244" 17.207388
    "1099250006275" 18.172617
    "1099250006305" 19.501144
    "1099250006374" 19.584696
    "1099250006398" 16.620935
    "1099250006435" 19.601484
    "1099250006558" 18.326319
    "1099250006732" 17.016905
    "1099250006749"  21.97266
    "1099250006787" 17.824898
    "1099250006794" 17.189758
    "1099250006909" 16.591694
    "1099250006916" 18.457619
    "1099250006923"  19.51468
    "1099250006985" 17.643011
    end

  • #2
    I'm guessing it is because FFMI has too many possible values. The help for levelsof says "levelsof may hit the limits imposed by your Stata. However, it is typically used when the number of distinct values of varname is not extremely large."
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 19.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      I also guess that there are too many levels; somewhere above 250. But it is probably not levelsof that chokes here (it should be able to handle many more levels). My guess is that the at() option of xblc (probably from SJ?), to which the levels are fed, cannot handle the number of levels.

      Comment


      • #4
        The problems isn't replicable because not all the variables are included in the dataex extract.

        I would probably have the program set to stop immediately after the levelsof command, so you could see if it was already bombing at that point.

        I suspect that, whether it runs or not, the command

        levelsof FFMI, local(levels)

        is mistaken anyway. Just with the data presented the value of FFMI is uniquie, i.e. you already have 100 levels with only 100 cases. I bet you meant to use some other variable here; or, you are just misunderstanding how to do what you want to do.

        In the help examples for the xblc command, in the -at- option they only list a few of the possible values for covname() variable, not every possible value. I suspect Sigrid wants to do the same.

        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          Dear Mr. William and mr. Klein,

          Thank you for valuable input. The syntax above works fine with the variable Ffm_NT4BLM, but not FFMI which is derived from it. How could the number of levels be different between these two?

          Code:
          gen Height_m = Hei_NT4BLM/100
          gen FFMI = ((Ffm_NT4BLM)/(Height_m^2))

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input double(Hei_NT4BLM Ffm_NT4BLM) float FFMI
          180.5   66 20.257673
            159 41.5  16.41549
          172.7 48.5 16.261368
          163.7 50.5 18.844908
          187.4   67 19.078123
          149.8 37.5 16.711199
          167.2   45 16.096815
          160.1   44 17.166037
          185.4 79.5  23.12851
          162.4 44.5 16.872831
            183   71  21.20099
          161.7   48 18.357824
          158.1 37.5 15.002635
          174.3 50.5 16.622509
          173.4   48  15.96405
          159.7   44 17.252134
          154.4   45 18.876345
          169.8   49 16.994984
          187.8 71.5  20.27285
          183.8   84  24.86499
          151.7 35.5 15.426138
          180.7   67  20.51911
            186   74 21.389755
          174.2 57.5 18.948357
            177 64.5 20.587954
          151.5   39 16.991798
            170 65.5  22.66436
          168.1   49 17.340462
          182.9 70.5 21.074715
          160.4   38  14.76981
          176.9 63.5  20.29168
          176.8   65  20.79452
          175.2   48 15.637706
          160.8 35.5 13.729548
          183.5 82.5 24.500887
          172.7   53 17.770155
            166 48.5 17.600523
          156.9 40.5 16.451637
          177.1   71  22.63712
          175.1 59.5 19.406385
          161.6 43.5 16.657373
            199 79.5  20.07525
          164.5 48.5 17.922968
            180   61 18.827162
          168.5 47.5  16.72992
          171.1   46 15.712954
          161.4 48.5 18.618073
          165.2   44 16.122509
          180.6   75 22.994595
          182.5   65 19.515856
          165.4 39.5 14.438632
          157.8 42.5 17.067698
          155.5 41.5 17.162767
          178.7 64.5 20.198105
          176.5 68.5  21.98878
          173.3   62 20.644033
          181.6 64.5  19.55816
          164.2 51.5 19.101213
          176.1 61.5  19.83154
          158.7   37 14.690882
            170   49 16.955017
          163.2   51 19.148285
          179.4 63.5  19.73008
          169.2 51.5 17.988977
          166.6   46 16.573256
          166.6 49.5 17.834265
          170.2 50.5 17.433004
          191.6   77  20.97489
          177.1   57 18.173464
          187.7 77.5  21.99749
          182.1 63.5  19.14934
          157.3 41.5 16.772224
          162.8   42  15.84676
          186.2   77  22.20912
          168.3   45 15.887088
          172.8   53 17.749592
          159.6 43.5 17.077469
          182.4   71   21.3407
          160.4   42 16.324526
          181.4 65.5  19.90521
          176.8   63 20.154686
          164.3   45 16.670069
          168.6 58.5  20.57978
          164.3 48.5 17.966629
            186   86 24.858364
          180.4   56 17.207388
          159.1   46 18.172617
          173.2 58.5 19.501144
          170.6   57 19.584696
          171.7   49 16.620935
          182.8 65.5 19.601484
            166 50.5 18.326319
          160.8   44 17.016905
            192   81  21.97266
          165.8   49 17.824898
          171.4 50.5 17.189758
          165.6 45.5 16.591694
          162.1 48.5 18.457619
          164.8   53  19.51468
          165.8 48.5 17.643011
          end

          Comment


          • #6
            The syntax above works fine with the variable Ffm_NT4BLM, but not FFMI which is derived from it. How could the number of levels be different between these two?
            It isn't like you are converting from feet to inches. There isn't a one to one correspondence between the two variables. Because you divide the original variable by Height_m^2, which has a huge number of unique values, FFMI could easily wind up with a unique value for every single case. See the following:

            Code:
            . levelsof Ffm_NT4BLM, local(levels1)
            35.5 37 37.5 38 39 39.5 40.5 41.5 42 42.5 43.5 44 44.5 45 45.5 46 47.5 48 48.5 49 49.5 50.5 51 51.5 53 56 57 57.5 58.5 59.5 61 61.5 62 63 63
            > .5 64.5 65 65.5 66 67 68.5 70.5 71 71.5 74 75 77 77.5 79.5 81 82.5 84 86
            
            . di r(r)
            53
            
            . levelsof FFMI, local(levels2)
            13.72954845428467 14.43863201141357 14.69088172912598 14.76980972290039 15.00263500213623 15.42613792419434 15.63770580291748 15.71295356750
            > 488 15.84675979614258 15.88708782196045 15.96405029296875 16.09681510925293 16.12250900268555 16.26136779785156 16.32452583312988 16.41548
            > 919677734 16.45163726806641 16.57325553894043 16.59169387817383 16.62093544006348 16.62250900268555 16.65737342834473 16.67006874084473 16
            > .7111988067627 16.72991943359375 16.77222442626953 16.87283134460449 16.95501708984375 16.99179840087891 16.9949836730957 17.0169048309326
            > 2 17.06769752502441 17.07746887207031 17.16276741027832 17.16603660583496 17.18975830078125 17.20738792419434 17.25213432312012 17.3404617
            > 3095703 17.43300437927246 17.60052299499512 17.64301109313965 17.74959182739258 17.77015495300293 17.82489776611328 17.83426475524902 17.9
            > 229679107666 17.96662902832031 17.98897743225098 18.17261695861816 18.17346382141113 18.32631874084473 18.35782432556152 18.45761871337891
            >  18.61807250976563 18.82716178894043 18.84490776062012 18.87634468078613 18.94835662841797 19.07812309265137 19.1012134552002 19.148284912
            > 10938 19.14933967590332 19.40638542175293 19.50114440917969 19.51468086242676 19.51585578918457 19.55816078186035 19.58469581604004 19.601
            > 48429870605 19.73007965087891 19.83153915405273 19.90521049499512 20.07525062561035 20.15468597412109 20.19810485839844 20.2576732635498 2
            > 0.27285003662109 20.29167938232422 20.51910972595215 20.57978057861328 20.58795356750488 20.64403343200684 20.79451942443848 20.9748897552
            > 4902 21.07471466064453 21.20099067687988 21.34070014953613 21.38975524902344 21.97266006469727 21.98877906799316 21.99748992919922 22.2091
            > 1979675293 22.63711929321289 22.66436004638672 22.99459457397461 23.12850952148438 24.50088691711426 24.85836410522461 24.864990234375
            
            . di r(r)
            100
            If you have hundreds or thousands of cases the results will be even more striking.

            I don't know what you are trying to do, but in the examples for xblc, they plugged in a set of 10 possible values, not hundreds or thousands.
            -------------------------------------------
            Richard Williams, Notre Dame Dept of Sociology
            StataNow Version: 19.5 MP (2 processor)

            EMAIL: [email protected]
            WWW: https://www3.nd.edu/~rwilliam

            Comment

            Working...
            X