Announcement

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

  • Reshape using string variables

    Hi: I have a data set in the following format:

    C GDP Y15
    x1 gdp1 20
    x1 gdp2 30
    x1 gdp3 40
    x2 gdp1 25
    x2 gdp2 35
    x2 gdp3 45
    x3 gdp1 15
    x3 gdp2 25
    x3 gdp3 35

    Trying to get it in the form below (variable names can of course be different):

    C gdp1_y15 gdp2_y15 gdp3_y15
    x1 20 30 40
    x2 25 35 45
    x3 15 25 35

    Tried the following command: reshape wide Y15, i(C) j(GDP) string -- but it doesn't work. Not having success with other variations either. Any ideas?

    Apologies in advance for any amateurish mistakes.

    Zaki Eusufzai
    Dept. of Economics
    Loyola Marymount University

  • #2
    try the following:
    Code:
    gen gdpnum=real(substr(GDP,-1,.)
    and then try your reshape but now with "j(gdpnum)"

    Comment


    • #3
      That works for me, so you need to show an example that doesn't work, or else explain what "doesn't work" means exactly. (FAQ Advice applies!)

      Code:
      clear 
      input str2 C str4 GDP Y15
      x1 gdp1 20
      x1 gdp2 30
      x1 gdp3 40
      x2 gdp1 25 
      x2 gdp2 35
      x2 gdp3 45
      x3 gdp1 15
      x3 gdp2 25
      x3 gdp3 35
      end 
      
      reshape wide Y15, i(C) j(GDP) string 
      
      list 
           +----------------------------------+
           |  C   Y15gdp1   Y15gdp2   Y15gdp3 |
           |----------------------------------|
        1. | x1        20        30        40 |
        2. | x2        25        35        45 |
        3. | x3        15        25        35 |
           +----------------------------------+

      Comment


      • #4
        Thanks, Rich and Nick. I understand now that the issue seems to be with the manner the GDP variable values are stored/denoted/called.

        Comment

        Working...
        X