Announcement

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

  • "using data not sorted" when using stptime

    Dear Statalisters,

    I am trying to generate Standardised mortality ratios (SMRs) by alcohol-use cohort groups.

    I am using Stata/SE14.1.

    my dataset looks like this.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long patid byte(gender cohort) float indexdate int exitdate byte(death _st _d) double(_origin _t) byte _t0
    20767109 1 4 18079.32 20426 0 1 0      18079.3203125  6.425034737432921 0
    27783206 1 4 17349.32 20446 0 1 0      17349.3203125  8.478479048023218 0
    11762154 1 4  5296.32 12075 0 1 0   5296.31982421875 18.559522987025655 0
     2611322 1 3 -3104.68 20447 0 1 0 -3104.679931640625  64.48275088062815 0
    55991525 1 4 18079.32 20439 0 1 0      18079.3203125  6.460627772149819 0
     9637473 1 2 13331.32 20439 0 1 0      13331.3203125 19.460299221060126 0
    22185415 1 1 17714.32 18197 0 1 0      17714.3203125 1.3215411441791698 0
     3041518 1 3 15888.32 19015 0 1 0      15888.3203125   8.56061682044683 0
     7268556 1 4  1643.32 19785 0 1 0 1643.3199462890625 49.670572921122925 0
    12960427 1 3 13696.32 18415 0 1 0      13696.3203125 12.919394610393166 0
    end
    format %td indexdate
    format %td exitdate
    label values gender genderlab
    label def genderlab 1 "male", modify
    label values cohort cohortlab
    label def cohortlab 1 "lifetime-abstainer", modify
    label def cohortlab 2 "low-risk", modify
    label def cohortlab 3 "hazardous", modify
    label def cohortlab 4 "AUD", modify
    label values death yesnolab
    label def yesnolab 0 "no", modify


    I am trying to run what I hope could be a way to generate SMRs by cohort group using the command

    Code:
    stptime, by(cohort) per(1000) smr(age popdist) using(analysis/eurostandpop)
    the eurostandpop is the european standard population 2013 (http://ec.europa.eu/eurostat/documen...d-5e8fa09b3f8f)


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte age int pop double popdist
    15 5500  .06547619047619048
    20 6000  .07142857142857143
    25 6000  .07142857142857143
    30 6500  .07738095238095238
    35 7000  .08333333333333333
    40 7000  .08333333333333333
    45 7000  .08333333333333333
    50 7000  .08333333333333333
    55 6500  .07738095238095238
    60 6000  .07142857142857143
    65 5500  .06547619047619048
    70 5000  .05952380952380952
    75 4000 .047619047619047616
    80 2500  .02976190476190476
    85 1500 .017857142857142856
    90  800 .009523809523809525
    95  200 .002380952380952381
    end

    However, this command seems to return the error

    Code:
    using data not sorted
    r(5);
    Would appreciate any help with helping me obtain SMRs for the alcohol cohort groups with stptime by solving the above or any other suitable advice or commands.

    Thank you in advance for your kind help.

    Yours truly,

    Kareem

  • #2
    OK, you have stumbled over a quasi-bug in -stptime-. The syntax error arises when -stptime- attempts to use the -merge- command, due to conflicting expectations about versioning.

    In modern versions of Stata, -merge- does not require the data sets involved to be pre-sorted: the sorting is done behind the scenes if needed. But -stptime- dates back to (at least) version 7, and begins by specifying version 7 syntax as governing within its scope. Back in version 7, data sets had to be separately sorted before you could -merge- them. When you use the version 7 syntax (that is, -merge keyvars using using_file- as opposed to modern -merge 1:1 keyvars usng using_file-), the old requirement for sorting is resurrected. It looks like the code for -stptime- hasn't been modified to account for newer usage.

    As a workaround for you, before you run -stptime- sort the -using()- data file on your -by()- variable and I think it will run without problems.

    StataCorp may want to update the code in -stptime- so that when run on a later version of Stata, the pre-sorting is no longer needed.

    Comment

    Working...
    X