Announcement

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

  • Possible bug in -reshape-

    I am encountering an error when using -reshape- with 'favor(speed)' when subsetting j. Using 'favor(memory)' works as expected which leads me to suspect a bug? Running on Windows/MP18.5 (revision 2024-12-18).)

    Silly example:
    Code:
    sysuse bplong.dta, clear
    reshape wide bp, i(patient) j(when 2) favor(speed)
    This throws the following error:
    Code:
    _reshape_df::increment_j():  3301  subscript invalid
    Last edited by Robert Ulbricht; 14 Jan 2025, 15:16.

  • #2
    Thank you for providing a minimal example. We will look into this and hopefully fix it soon.

    Comment


    • #3
      This does seem to be a bug. I can replicate the findings reported in #1 on my setup. (Windows 10, Stata MP4 version 18.5)
      Interestingly, if you list out all of the values of the -j()- variable, then the code does not throw an error. Similarly, if you first -keep if inlist(bp, 138, 141)- and run the code exactly as shown in #1, you also get no error. But it does seem that the -favor(speed)- version is not recognizing partial subset lists correctly.

      Added: Crossed with #2.

      Comment


      • #4
        This has been fixed in the Stata 18 update on 26feb2025.

        Comment


        • #5
          Thanks for providing a fix. I can confirm that the original bug has been fixed in that update.

          However, there seems to have been a regression in Stata 19 where -reshape- now fails again under a similar set of circumstances.

          I am attaching a full reproducer below.

          Code:
          /*
           * This is a minimal reproducer for the reshape bug on Stata 19.
           *
           * Setting `J' to 10 or less, or setting favor(memory) avoids the bug,
           * and produces the following dataset:
           *
           * . list  /* Result from `J' = 11 and favor(memory) */
           *
           *      +------------------------------------------------------+
           *      | i   x1   x2   x3   x4   x5   x6   x7   x8   x9   x10 |
           *      |------------------------------------------------------|
           *   1. | 1    0    0    0    0    0    0    0    0    0     0 |
           *      +------------------------------------------------------+
           *
           * Setting `J' to at least 11 AND setting favor(speed) causes a bug,
           * where the reshape fails with the following error:
           *
           * variable x2 not found
           *
           */
          
          version 19
          clear
           
          local J 11
          set obs `J'
          
          gen i = 1
          gen j = _n
          gen x = 0
          
          levelsof j if j < `J', local(values)
          reshape wide x, i(i) j(j `values') favor(speed)
          Last edited by Robert Ulbricht; 04 Aug 2025, 13:22.

          Comment


          • #6
            Thank you for providing a minimal example. We hope to have this fixed in the next update to Stata (18 and 19...).

            Comment

            Working...
            X