Announcement

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

  • Need help with Reshape!!! :(


    Hi guys,


    I have data that looks like this:
    ymd year month day time output
    200011 2000 1 1 12:00 0.123456
    200011 2000 1 1 13:00 0.987654
    200011 2000 1 1 14:00 0.456123
    200012 2000 1 2 12:00 0.789123
    200112 2001 1 2 13:00 0.963852
    200112 2001 1 2 14:00 0.852852
    And I need it to look like this:
    ymd year month day 12:00 13:00 14:00
    200011 2000 1 1 0.123456 0.987654 0.456123
    200012 2000 1 2 0.789123 0.963852 0.852852
    When I use the following command:

    "reshape wide output, i(ymd) j(time) string"

    I get the error:

    "output12:00 invalid variable name"



    Is there any way I can overcome this?

    Thanks,
    A

  • #2
    Drop the colon ':' from the time variable. This character isn't allowed in variable name. At least that is the case in Stata 13.1.
    Last edited by Jorrit Gosens; 16 Jun 2015, 03:48.

    Comment


    • #3
      Hello and welcome to the forum,
      Please read the FAQ especially 6.
      You can try the following code to avoid invalid characters in variable names.
      Code:
      ​forval i=12/14 {
          replace time ="a_`i'" if time=="`i':00"
      }
      reshape wide output , i(ymd)j(time, string)
      Last edited by Oded Mcdossi; 16 Jun 2015, 04:18.

      Comment


      • #4
        Despite good advice you have received, I doubt that a reshape wide is really a good idea for your kind of data. It usually makes analyses more difficult, not easier.

        P.S. I want to underline strongly our preference for full real names here, as pointed out by Oded. Please fix that.

        Comment


        • #5
          Thanks for the advice guys, and have requested a name change too.

          Nick Cox, I know this is not ideal for analysis, I'm actually just using stata to manipulate the data into this format so I can export it to excel again for the purposes of updating an existing file used for analysis is linked to heaps of excel workbooks!

          Comment

          Working...
          X