Announcement

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

  • Reshape command

    Hello,

    I would like some help with the reshape command, I have data which looks like this:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str3 country double(vnm_a01_02 vnm_a03 vnm_b05_06 vnm_b07_08 vnm_b09 vnm_c10t12)
    "CHN"  611.6579063033496 297.10939825867536  615.5062017014425  58.24620080894965  7.904399911050859 348.34770285943523
    "HKG" 14.877199930720963 3.0813000296402606 18.294999853067566  .8782000126302592 .21969999965222087 10.660499759360391
    "JPN" 201.91149829741335  37.30380023855105  263.0887982299537 11.991600114633911 3.6244999939081026  119.2262984412082
    "KOR"  329.4226014391752 161.45150118635502 320.56359891593456  23.16449951237155  4.768700014843489 152.67750062583946
    "TWN"  542.7227090717643  244.5491932502482 402.04210234899074  36.09100049704284  2.672700015922601 168.17570059979334
    "ROW"  4393.945826928437 1561.4524869715533 3029.5677002843513 249.93380123786483  38.44039996757783  4224.836292915221
    "VNM" 10922.357060905546  4041.086084922943 3677.3541818342346 298.11079993858584  78.21289978720597 25663.341336591337
    end

    Each variable other than 'country' represents an industry code, I would like each observation to be the industry code, and each variable to be the country, so I would have one variable called industry containing industry codes. And I would have 7 other variables, one for each country. Essentially I'm reversing the format. How can I implement this?

    Thanks,
    Jad

  • #2
    This is a standard reshape problem. To get from one wide layout to another you need to go through a long layout first.

    The only twist is a need to specify string.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str3 country double(vnm_a01_02 vnm_a03 vnm_b05_06 vnm_b07_08 vnm_b09 vnm_c10t12)
    "CHN"  611.6579063033496 297.10939825867536  615.5062017014425  58.24620080894965  7.904399911050859 348.34770285943523
    "HKG" 14.877199930720963 3.0813000296402606 18.294999853067566  .8782000126302592 .21969999965222087 10.660499759360391
    "JPN" 201.91149829741335  37.30380023855105  263.0887982299537 11.991600114633911 3.6244999939081026  119.2262984412082
    "KOR"  329.4226014391752 161.45150118635502 320.56359891593456  23.16449951237155  4.768700014843489 152.67750062583946
    "TWN"  542.7227090717643  244.5491932502482 402.04210234899074  36.09100049704284  2.672700015922601 168.17570059979334
    "ROW"  4393.945826928437 1561.4524869715533 3029.5677002843513 249.93380123786483  38.44039996757783  4224.836292915221
    "VNM" 10922.357060905546  4041.086084922943 3677.3541818342346 298.11079993858584  78.21289978720597 25663.341336591337
    end
    
    reshape long vnm_ , i(country) j(which) string 
    
    list, sepby(country)
    
    reshape wide vnm_, i(which) j(country) string 
    
    list, sepby(which)

    Comment

    Working...
    X