Announcement

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

  • Reshape Error

    Hi everyone,
    I am trying to reshape a dataset from long to wide.

    The unique ID is bs_pat_id and the sub-observations are event and unique by bs_pat_id.
    My variable event is numeric. And it DOES exist.
    I typed reshape error to check for errors.

    Please find below commands and results.

    Can anyone help?
    Thanks.

    Marie

    reshape wide (_all), i( bs_pat_id) j( event)
    (note: j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
    variable event not found
    r(111);

    . reshape error
    (note: j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
    event is unique within bs_pat_id;
    there is no error with which "reshape error" can help.

  • #2
    Welcome to the Stata Forum / Statalist.

    Please use the CODE delimiters so as to share data and command.

    You may wish to install the SSC dataex as well.

    By doing so, the odds of a helpful reply increase significantly.

    Edited to add: when using "_all", Stata may provide an error message for the "j" variable like yours.

    Code:
     
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float id byte year float(inc ue sex)
    1 80 5000 0 0
    1 81 5500 1 0
    1 82 6000 0 0
    2 80 2000 1 1
    2 81 2200 0 1
    2 82 3300 0 1
    3 80 3000 0 0
    3 81 2000 0 0
    3 82 1000 1 0
    end
      
    . reshape wide (_all), i(id) j( year)
    (note: j = 80 81 82)
    variable year not found
    r(111);
    
    . reshape wide inc ue, i(id) j( year)
    (note: j = 80 81 82)
    
    Data                               long   ->   wide
    -----------------------------------------------------------------------------
    Number of obs.                        9   ->       3
    Number of variables                   5   ->       8
    j variable (3 values)              year   ->   (dropped)
    xij variables:
                                        inc   ->   inc80 inc81 inc82
                                         ue   ->   ue80 ue81 ue82
    -----------------------------------------------------------------------------
    
    . list
    
         +-------------------------------------------------------+
         | id   inc80   ue80   inc81   ue81   inc82   ue82   sex |
         |-------------------------------------------------------|
      1. |  1    5000      0    5500      1    6000      0     0 |
      2. |  2    2000      1    2200      0    3300      0     1 |
      3. |  3    3000      0    2000      0    1000      1     0 |
         +-------------------------------------------------------+
    Last edited by Marcos Almeida; 15 Aug 2017, 07:23.
    Best regards,

    Marcos

    Comment


    • #3
      Thanks! I listed all the variables instead of _all and it worked.
      I'm working on a big dataset so I'll probably need to keep only the variables I'll actually need.
      However I'm sure there is a way for me to analyse my data without going through reshape etc... I'm a little rusty on Stata...

      "Please use the CODE delimiters so as to share data and command.
      You may wish to install the SSC dataex as well."
      I'm sorry I have no idea what you're talking about !

      Thanks
      Marie

      Comment


      • #4
        Marie Degail I'm glad my suggestion did solve the problem. With regards to CODE delimiters and the recommended way to share data, command and output (plus lots of important information, if you underline that
        I'm sorry I have no idea what you're talking about !
        it means you haven't yet clicked on the link to the "FAQ" (available in the top left corner).

        In #2, you have an example of CODE delimiters as well as the use of dataex.

        Acting in consonance with the FAQ recommendations is the expected etiquette in the forum. Please do read the FAQ. Thanks.

        Surely the odds of getting insighful replies increase significantly just by posting a query accordingly.
        Last edited by Marcos Almeida; 15 Aug 2017, 11:57.
        Best regards,

        Marcos

        Comment


        • #5
          However I'm sure there is a way for me to analyse my data without going through reshape etc... I'm a little rusty on Stata...
          Since you were looking to do a -reshape wide- it is highly likely that, not only is there a way to analyze your data without going through reshaping, that other way is likely to be easier, faster, and all-around better. There are only a few things in Stata that work better wide: graphing multiple y-axis variables against a single x-axis variable on the same graph, paired ttests (though these can be emulated with -xtreg, fe- in long layout), and exporting data to Excel when you want the spreadsheet itself in wide layout. -egen- has a large number of functions that work with wide data, but there is usually a corresponding function that also works with long. There are some others as well, but those are the most commonly encountered. The vast majority of data management and analysis commands in Stata are designed for use with long data.

          Since you don't say what you plan to do, no more specific advice can be offered.

          Comment


          • #6
            Hi,
            Thanks! I listed all the variables instead of _all and it worked.
            I'm working on a big dataset so I'll probably need to keep only the variables I'll actually need.
            If you have a big dataset to reshape, you can utilise
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear 
            input float id byte year float(inc ue sex age)
            1 80 5000 0 0 1
            1 81 5500 1 0 1
            1 82 6000 0 0 1    
            2 80 2000 1 1 3
            2 81 2200 0 1 3    
            2 82 3300 0 1 3
            3 80 3000 0 0 2    
            3 81 2000 0 0 2
            3 82 1000 1 0 2
            end
            *reshape _all without j "year"
            . reshape wide (inc-age), i(id) j(year)

            Comment

            Working...
            X