Announcement

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

  • Transforming dataset with several variables and a 'value' variable

    Dear all,

    I have a problem in Stata that I have been struggling with for quite some time now.
    As you can see in the screenshot I have a database whereby I have a variable 'Item' which includes seven characteristics belonging to a certain company in a certain year (such as employees, sales, profit etc). I have a seperate variable called 'value' whereby the value of these Item variables is displayed. I however want to have my dataset in the form whereby the Item characteristics are seperate variables, and their values are displayed for every company observation in the given year.

    I have tried to transform my data, but I cannot get the values of the Item characteristics displayed for all years of the company, but only for when the 'Item' equals the certain characteristic (see screenshot).

    Can someone help me with a command or way to get this right?

    Thank you very much in advance.

    Kind regards,
    Nathalie
    Attached Files

  • #2
    Please see FAQ Advice #12 at http://www.statalist.org/forums/help#stata for why screenshots are not nearly as helpful as you hope and what to do instead.

    The word "transform" usually implies some transformation of individual variables, not a major change in the structure of a dataset.

    The following toy example should help. A reshape wide is another solution.

    Code:
    clear
    input str1 id float(time y1 y2 y3)
    "a" 1 4 . .
    "a" 1 . 5 .
    "a" 1 . . 6
    "b" 2 7 . .
    "b" 2 . 8 .
    "b" 2 . . 9
    end
    
    collapse y1 y2 y3, by(id time)
    
    list
    
         +--------------------------+
         | id   time   y1   y2   y3 |
         |--------------------------|
      1. |  a      1    4    5    6 |
      2. |  b      2    7    8    9 |
         +--------------------------+
    .

    Comment


    • #3
      Nathalie:
      -reshape- is a probably the command to get what you're presumably after.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment

      Working...
      X