Announcement

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

  • reshape wide



    Dear Prof and colleagues,

    I have variables:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str24 country int year float(IM_hat1 IM_hat2 IM_hat3 IM_hat4 IM_hat5 IM_hat6 IM_hat7)
    "Angola" 2010 .0019409563 .0026657765   .00278101 .0014481426  .002601358 .0011470438  .002330335
    "Angola" 2011  .001786784 .0024531425 .0025291746 .0013371214  .002343533 .0010525389 .0021250814
    "Angola" 2012 .0016688402   .00228945  .002346451 .0012528986 .0021485733 .0009800441 .0019774805
    "Angola" 2013 .0016827296 .0023080825  .002352828 .0012655797 .0021243102 .0009851087 .0019953148
    "Angola" 2014 .0016508705  .002267136 .0022933816  .001245773 .0020581249 .0009643025 .0019646205
    "Angola" 2015  .001541956 .0021211824 .0021280942 .0011680163 .0019056046 .0009013093  .001848747
    "Angola" 2016  .001445331 .0019922007 .0019762006 .0011000333 .0017789187 .0008474067  .001750199
    "Angola" 2017 .0014411852  .001992706  .001956317 .0011032786  .001783095 .0008476267 .0017594364
    "Angola" 2018  .001579247 .0021915447 .0021359292 .0012176912 .0019642147  .000931427 .0019402442
    "Angola" 2019 .0019556207  .002721579  .002659298 .0015184585  .002458236 .0011554575 .0024117206
    end
    I need to reshape them as:
    Code:
    country   year    region    IM_hat
    Angola    2010     1       .001941
    Angola    2010     2       .0026658
    Angola    2010     3       .002781
    .
    .
    . 
    Angola    2010     7     .0023303 
    
    Angola    2011     1      .0017868
    Angola    2011     2      .0024531
    Angola    2011     3      .0025292
    .
    .
    .
    Angola    2011    7    .0021251
    .
    .
    .
    Angola    2019     1   .0019556
    .
    .
    . 
    Angoal    2019     7   .0024117
    Any ideas appreciated.

    Cheers,
    Paris

  • #2
    I won't lie to you, I'm 26 years old, and I've used Stata for 7 years, and sometimes even I must refer back to this page.

    Comment


    • #3
      Your data are already in a wide format and you seek to make them into a long(er) format. The command you need is -reshape long-.

      Code:
      reshape long IM_hat, i(country year) j(region)

      Comment


      • #4
        Dear Jared and Leo, thank you for getting back to me. #3 worked perfectly.

        Comment

        Working...
        X