Announcement

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

  • Reshape wide with missing observations

    Hello,

    I am trying to reshape wide the dataset below. Basically i would like the months (January through December) to be individual columns. However, some of the months are missing within "year" (ranges from 2013-2020) and within "ori". I would just like the missing months to show up either as 0 or blank.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str9 ori int year float month double n_incidents
    "AL0011200" 2013  1 339
    "AL0011200" 2013  2 351
    "AL0011200" 2013  3 334
    "AL0011200" 2013  4 327
    "AL0011200" 2013  5 385
    "AL0011200" 2013  6 434
    "AL0011200" 2013  7 391
    "AL0011200" 2013  8 343
    "AL0011200" 2013  9 388
    "AL0011200" 2013 10 425
    "AL0011200" 2013 11 337
    "AL0011200" 2013 12 375
    end
    label values month month1
    label def month1 1 "January", modify
    label def month1 2 "February", modify
    label def month1 3 "March", modify
    label def month1 4 "April", modify
    label def month1 5 "May", modify
    label def month1 6 "June", modify
    label def month1 7 "July", modify
    label def month1 8 "August", modify
    label def month1 9 "September", modify
    label def month1 10 "October", modify
    label def month1 11 "November", modify
    label def month1 12 "December", modify

    Any help with the syntax would be greatly appreciated!

  • #2
    Code:
    reshape wide n_incidents, i(ori year) j(month)
    The missing months will show up as missing values.

    Let me just point out, however, that most Stata data management and analysis commands work better, or only, in the long layout you have started with. The wide layout you are seeking to create has very limited usefulness in Stata. So unless you are certain that you will be doing some of the few things for which the wide layout is better in Stata, I recommend you not do this.

    Comment

    Working...
    X