Announcement

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

  • Reshape, panel structure

    Hi, I have some problem with the reshape command that I can´t solve. What I want to do is to create two new variables from the example data bellow, v1 and v2, but still have the panel structure of different variables over id and year.

    ID year variable_name value
    1 2010 v1 ..
    1 2011 v1 ..
    1 2012 v1 ..
    1 2010 v2 ..
    1 2011 v2 ..
    1 2012 v2 ..
    2 2010 v1
    ......

  • #2
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte ID int year str13 variable_name str5 value
    1 2010 "v1" ".."
    1 2011 "v1" ".."
    1 2012 "v1" ".."
    1 2010 "v2" ".."
    1 2011 "v2" ".."
    1 2012 "v2" ".."
    2 2010 "v1" ""  
    end
    
    reshape wide value, i(ID year) j(variable_name) string
    rename value* *
    xtset ID year
    Res.:

    Code:
    . xtset ID year
           panel variable:  ID (unbalanced)
            time variable:  year, 2010 to 2012
                    delta:  1 unit
    
    . l, sepby(ID)
    
         +---------------------+
         | ID   year   v1   v2 |
         |---------------------|
      1. |  1   2010   ..   .. |
      2. |  1   2011   ..   .. |
      3. |  1   2012   ..   .. |
         |---------------------|
      4. |  2   2010           |
         +---------------------+

    Comment


    • #3
      Hi! It worked perfectly. Thank you so much Andrew!
      /David

      Comment

      Working...
      X