Announcement

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

  • Problem with permute: error __000005 not found

    Dear Statalists!

    I am using permute in Stata 13.0 and Stata issues the error message "__000005 not found" which I can't interpret. I've searched the error, but only found some unrelated posts.
    I've already tried using set trace on, but I could not identify the error.


    It would be great if you could help me to find the error in my code. I use the forum for the first time and hope I provided all the necessary information. I am happy to add any missing information.

    Thank you very much in advance!

    Code:

    use dataplus.dta, replace
    drop if (treat==1|treat==2)
    collapse (sum) vote (mean) treat (count)n=vote, by (group totalmessage)


    // Program to calculate test statistic
    capture program drop meansum
    program meansum, rclass
    args y group
    collapse (sum) `y' n, by (`group' totalmessage)
    sort totalmessage `group'
    gen diff=.
    local p=1
    while `p' < 9 {
    replace diff=((`y'/n)-(`y'[`p'+ 1]/n[`p'+ 1]))*(n+n[`p'+ 1]) in `p'
    local p = `p' + 2
    }
    return scalar summe = diff[1]+diff[3]+diff[5]+diff[7]
    end
    //

    set seed 12345

    /* stata permute command */
    permute treat meansum = r(summe), reps(1000): meansum vote treat // this executes the program meansum; vote is "y" and treat is "group" in the programm

  • #2

    Your program collapses the data first time it is called by permute.

    What happens second time? I think you may need to read in the original dataset again. That's may be the root of the difficulty.

    I have only rarely used permute, so this is just a guess.

    But your program is difficult to read, given that (1) you didn't use CODE delimiters as requested (2) by accident it includes some HTML garbage.



    Comment


    • #3
      Hi Nick!

      Thank you for your suggestion! Itried to read in the original dataset again, but it did not work. When I use trace on, I can see that permute executes the program twice and then the error appears.
      Funnily, now I get the error message "__000003 not found" and not as previously "__000005 not found"


      Below you find the updated program (this time I hope it is readable). Thank you very much for your effort!


      Code:
      capture program drop meansum
      program meansum, rclass
      args y grouping
      use permdata.dta, replace
      collapse (sum) `y' n, by (`grouping' totalmessage)
      sort totalmessage `grouping'
      gen diff=.
      local p=1
      while `p' < 9 {
                 replace diff=((`y'/n)-(`y'[`p'+ 1]/n[`p'+ 1]))*(n+n[`p'+ 1]) in `p'             
                 local p = `p' + 2
              }
      return scalar summe = diff[1]+diff[3]+diff[5]+diff[7]
      
      end
      
      permute treat meansum = r(summe), reps(1000): meansum vote treat

      Comment


      • #4
        A user reading this can look through your program and try to see obvious errors or something that could be problematic. My guess was seemingly off-target and looking through the code I still can see nothing obviously wrong. That means only what it says.

        The problem now is that your problem is not reproducible by us unless we have your dataset, but we don't; and we would have to work at trying to guess what the dataset might look like, but that's too much like effort. So, one option is that you make that dataset accessible, or equivalently provide data with which the problem can be reproduced.

        Further, the error messages you get concern temporary names and it is hard to know what they refer to. Another option is that you set trace on to try to find where the error occurs.

        Comment


        • #5
          Hi Nick!

          I would like to upload the dataset, but everytime I try I get the notice "This is not a valid image file."
          I tried to upload the data file as .dta, .csv, .xls and .jpg from three different browsers (Chrome, Firefox, IE).

          Is there currently a problem?


          Below I post an extract from the set trace on results to show where the error occurs. I am not sure whether this is helpful...


          Code:
               }
                -------------------------------------------------- end _dots ---
              - }
              - if `binary' {
              = if 1 {
              - PermDiV "`strata'" `v' `min' `max' `permvar'
              = PermDiV "" __000003 __000004 __000005 treat
                -------------------------------------- begin permute.PermDiV ---
                - version 9
                - args strata k min max x
                - tempvar y
                - if "`strata'"!="" {
                = if ""!="" {
                  sort `strata'
                  local bystrata "by `strata':"
                  }
                - quietly {
                - gen byte `y' = . in 1
                = gen byte __000006 = . in 1
                - `bystrata' replace `y' = uniform()<(`k'-sum(`y'[_n-1]))/(_N-_n
          > +1)
                =  replace __000006 = uniform()<(__000003-sum(__000006[_n-1]))/(
          > _N-_n+1)
          __000003 not found
                  replace `x' = cond(`y',`max',`min')
                  }
                ---------------------------------------- end permute.PermDiV ---
                }
                else {

          Comment


          • #6
            It's small progress. The problem is within permute and one of the arguments to a program is undefined.

            We do not want to see data as any kind of image; that's no use to us. It's best to show data explicitly within CODE listings.

            Comment


            • #7
              Thanks for your patience. I am new to Statalist, so it takes me some time to figure out how it works.
              I've pasted the data within CODE and hope this is the format you wanted...

              Code:
              group    totalmessage    vote    treat    n
              25    0    0    3    30
              25    1    2    3    39
              25    2    30    3    30
              25    3    21    3    21
              26    0    0    3    21
              26    1    13    3    60
              26    2    30    3    30
              26    3    9    3    9
              27    0    0    3    9
              27    1    15    3    48
              27    2    29    3    33
              27    3    30    3    30
              28    0    1    3    27
              28    1    6    3    33
              28    2    42    3    42
              28    3    18    3    18
              29    0    2    3    12
              29    1    11    3    36
              29    2    46    3    51
              29    3    17    3    21
              30    0    1    3    15
              30    1    8    3    33
              30    2    51    3    54
              30    3    18    3    18
              31    0    1    3    18
              31    1    10    3    39
              31    2    47    3    48
              31    3    15    3    15
              32    0    1    3    3
              32    1    14    3    45
              32    2    40    3    42
              32    3    30    3    30
              33    0    1    4    3
              33    1    29    4    51
              33    2    31    4    48
              33    3    15    4    18
              34    0    6    4    15
              34    1    26    4    45
              34    2    28    4    51
              34    3    7    4    9
              35    1    20    4    33
              35    2    30    4    54
              35    3    22    4    33
              36    0    1    4    3
              36    1    9    4    18
              36    2    41    4    72
              36    3    23    4    27
              37    0    0    3    24
              37    1    8    3    39
              37    2    23    3    24
              37    3    33    3    33
              38    0    0    3    6
              38    1    8    3    45
              38    2    42    3    42
              38    3    27    3    27
              39    0    0    3    27
              39    1    5    3    36
              39    2    25    3    27
              39    3    30    3    30
              40    0    3    3    15
              40    1    17    3    27
              40    2    47    3    48
              40    3    30    3    30
              41    0    0    3    33
              41    1    4    3    21
              41    2    37    3    39
              41    3    27    3    27
              42    0    1    3    24
              42    1    8    3    48
              42    2    29    3    33
              42    3    15    3    15
              43    0    0    3    21
              43    1    5    3    48
              43    2    28    3    30
              43    3    21    3    21
              44    0    0    3    12
              44    1    17    3    30
              44    2    42    3    45
              44    3    33    3    33
              45    0    4    4    9
              45    1    18    4    33
              45    2    37    4    66
              45    3    7    4    12
              46    0    4    4    12
              46    1    5    4    9
              46    2    34    4    66
              46    3    26    4    33
              47    0    6    4    12
              47    1    30    4    51
              47    2    26    4    48
              47    3    8    4    9
              48    0    2    4    3
              48    1    10    4    18
              48    2    42    4    75
              48    3    14    4    24
              49    0    2    4    6
              49    1    22    4    42
              49    2    40    4    60
              49    3    12    4    12
              50    0    5    4    15
              50    1    34    4    48
              50    2    22    4    39
              50    3    17    4    18
              51    0    6    4    12
              51    1    20    4    39
              51    2    30    4    51
              51    3    12    4    18
              52    0    3    4    6
              52    1    13    4    24
              52    2    36    4    60
              52    3    19    4    30
              53    0    3    4    6
              53    1    21    4    33
              53    2    37    4    63
              53    3    17    4    18
              54    0    2    4    6
              54    1    10    4    27
              54    2    36    4    66
              54    3    19    4    21
              55    0    2    4    6
              55    1    14    4    27
              55    2    35    4    66
              55    3    16    4    21
              56    0    7    4    21
              56    1    24    4    45
              56    2    26    4    45
              56    3    6    4    9

              Comment


              • #8
                With that and your previous we now have a script for a reproducible example.

                Code:
                clear
                input group    totalmessage    vote    treat    n
                25    0    0    3    30
                25    1    2    3    39
                25    2    30    3    30
                25    3    21    3    21
                26    0    0    3    21
                26    1    13    3    60
                26    2    30    3    30
                26    3    9    3    9
                27    0    0    3    9
                27    1    15    3    48
                27    2    29    3    33
                27    3    30    3    30
                28    0    1    3    27
                28    1    6    3    33
                28    2    42    3    42
                28    3    18    3    18
                29    0    2    3    12
                29    1    11    3    36
                29    2    46    3    51
                29    3    17    3    21
                30    0    1    3    15
                30    1    8    3    33
                30    2    51    3    54
                30    3    18    3    18
                31    0    1    3    18
                31    1    10    3    39
                31    2    47    3    48
                31    3    15    3    15
                32    0    1    3    3
                32    1    14    3    45
                32    2    40    3    42
                32    3    30    3    30
                33    0    1    4    3
                33    1    29    4    51
                33    2    31    4    48
                33    3    15    4    18
                34    0    6    4    15
                34    1    26    4    45
                34    2    28    4    51
                34    3    7    4    9
                35    1    20    4    33
                35    2    30    4    54
                35    3    22    4    33
                36    0    1    4    3
                36    1    9    4    18
                36    2    41    4    72
                36    3    23    4    27
                37    0    0    3    24
                37    1    8    3    39
                37    2    23    3    24
                37    3    33    3    33
                38    0    0    3    6
                38    1    8    3    45
                38    2    42    3    42
                38    3    27    3    27
                39    0    0    3    27
                39    1    5    3    36
                39    2    25    3    27
                39    3    30    3    30
                40    0    3    3    15
                40    1    17    3    27
                40    2    47    3    48
                40    3    30    3    30
                41    0    0    3    33
                41    1    4    3    21
                41    2    37    3    39
                41    3    27    3    27
                42    0    1    3    24
                42    1    8    3    48
                42    2    29    3    33
                42    3    15    3    15
                43    0    0    3    21
                43    1    5    3    48
                43    2    28    3    30
                43    3    21    3    21
                44    0    0    3    12
                44    1    17    3    30
                44    2    42    3    45
                44    3    33    3    33
                45    0    4    4    9
                45    1    18    4    33
                45    2    37    4    66
                45    3    7    4    12
                46    0    4    4    12
                46    1    5    4    9
                46    2    34    4    66
                46    3    26    4    33
                47    0    6    4    12
                47    1    30    4    51
                47    2    26    4    48
                47    3    8    4    9
                48    0    2    4    3
                48    1    10    4    18
                48    2    42    4    75
                48    3    14    4    24
                49    0    2    4    6
                49    1    22    4    42
                49    2    40    4    60
                49    3    12    4    12
                50    0    5    4    15
                50    1    34    4    48
                50    2    22    4    39
                50    3    17    4    18
                51    0    6    4    12
                51    1    20    4    39
                51    2    30    4    51
                51    3    12    4    18
                52    0    3    4    6
                52    1    13    4    24
                52    2    36    4    60
                52    3    19    4    30
                53    0    3    4    6
                53    1    21    4    33
                53    2    37    4    63
                53    3    17    4    18
                54    0    2    4    6
                54    1    10    4    27
                54    2    36    4    66
                54    3    19    4    21
                55    0    2    4    6
                55    1    14    4    27
                55    2    35    4    66
                55    3    16    4    21
                56    0    7    4    21
                56    1    24    4    45
                56    2    26    4    45
                56    3    6    4    9
                end
                
                save isabelmarc, replace
                
                capture program drop meansum
                program meansum, rclass
                args y grouping
                use isabelmarc.dta, replace
                collapse (sum) `y' n, by (`grouping' totalmessage)
                sort totalmessage `grouping'
                gen diff=.
                local p=1
                while `p' < 9 {
                           replace diff=((`y'/n)-(`y'[`p'+ 1]/n[`p'+ 1]))*(n+n[`p'+ 1]) in `p'            
                           local p = `p' + 2
                        }
                return scalar summe = diff[1]+diff[3]+diff[5]+diff[7]
                end
                
                permute treat meansum = r(summe), reps(1000): meansum vote treat
                At this point, I bow out. Either someone bites or you have something that you can take to StataCorp technical support, but they may well have ground rules about debugging your programs if it seems that the problem is an indirect effect of your program.

                Comment


                • #9
                  Thank you, Nik for your support! I've rewritten the program to that I don't need the collapse command anymore. It is now much longer, but at least it works.

                  Comment


                  • #10
                    Actually, the problem stems from the fact that permute creates a temporary variable in the data before starting the repetitions. If your program clobbers the data to collapse, then permute stops at the second iteration because the temporary variable is not there anymore. An easy solution is to use preserve

                    Code:
                    capture program drop meansum
                    program meansum, rclass
                    
                    args y grouping
                    
                    preserve
                    
                    collapse (sum) `y' n, by (`grouping' totalmessage)
                    sort totalmessage `grouping'
                    gen diff=.
                    local p=1
                    while `p' < 9 {
                               replace diff=((`y'/n)-(`y'[`p'+ 1]/n[`p'+ 1]))*(n+n[`p'+ 1]) in `p'            
                               local p = `p' + 2
                            }
                    return scalar summe = diff[1]+diff[3]+diff[5]+diff[7]
                    
                    end

                    Comment


                    • #11
                      Robert: Good catch.

                      Comment


                      • #12
                        Thank you very much!

                        Comment

                        Working...
                        X