Announcement

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

  • Problem in reshaping the data

    Dear all,

    I provide you a dataex of mydataset in wide format.
    The first column measures the date
    You will see that all other columns are related to an identifier (identified with cusip as id).
    The value of each column related to identifier is a score.

    What I need to create is a panel as follow (I provide you an example of what I'm looking for):
    CUSIP_ DATE SCORE
    AAAA 31/12/2020 54.3
    AAAA 21/11/2019 52.1
    My identifiers (CUSIP) are more then 3000
    I recognize that the dataset which I'm working with is messy, but would love if someone can give me any advice

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int Dates double(CUSIP_000360206 CUSIP_000361105 CUSIP_000375204 CUSIP_000868109) byte CUSIP_000886309 double(CUSIP_000899104 CUSIP_000957100)
    14609                  .                  .                  .                  . .                  .                  .
    14975                  .                  .                  .                  . .                  .                  .
    15340                  .                  .                  .                  . .                  .                  .
    15705                  .                  .                  .                  . .                  .                  .
    16070                  .                  .                  .                  . .                  .                  .
    16436                  .                  .                  .                  . .                  .                  .
    16801                  .                  .  53.08319091796875                  . .                  .                  .
    17166                  .                  . 58.817020416259766                  . .                  .                  .
    17531                  .                  . 57.690372467041016                  . .                  .                  .
    17897                  .                  .  55.69862365722656                  . .                  .                  .
    18262                  .                  .  60.38628005981445                  . .                  .                  .
    18627 26.908761978149414                  .  60.33598327636719 27.743688583374023 .                  .                  .
    18992 26.908761978149414                  .  62.51885986328125 27.743688583374023 .                  .                  .
    19358 26.908761978149414                  .  62.51885986328125 27.743688583374023 .                  .                  .
    19723 26.908761978149414                  .  61.12061309814453 25.067901611328125 .                  .                  .
    20088 26.908761978149414                  .   64.5407943725586 27.743688583374023 .                  .                  .
    20453 28.397546768188477                  .  65.35559844970703 26.948999404907227 . 27.954933166503906                  .
    20819 28.397546768188477                  .  65.82838439941406     28.57861328125 . 30.620662689208984                  .
    21184 31.656774520874023                  .  65.82838439941406 31.556180953979492 .  31.45558738708496                  .
    21549 31.958555221557617                  .  66.66331481933594  32.48164367675781 .  31.45558738708496                  .
    21914 36.374610900878906                  .  66.66331481933594  32.48164367675781 .  31.45558738708496                  .
    22280  37.63203048706055                  .   66.2005844116211  32.48164367675781 .  31.45558738708496                  .
    14395                  .                  .                  .                  . .                  .                  .
    14761                  .                  .                  .                  . .                  .                  .
    15126                  .                  .                  .                  . .                  .                  .
    15491                  .                  .                  .                  . .                  .                  .
    15856                  .                  .                  .                  . .                  .                  .
    16222                  .                  .                  .                  . .                  .                  .
    16587                  .                  .                  .                  . .                  .                  .
    16952                  .                  .                  .                  . .                  .                  .
    17317                  .                  .                  .                  . .                  .                  .
    17683                  .                  .                  .                  . .                  .                  .
    18048                  .                  .                  .                  . .                  .                  .
    18413                  . 26.908761978149414                  .                  . .                  .                  .
    18778                  . 26.908761978149414                  .                  . .                  .                  .
    19144                  . 26.908761978149414                  .                  . .                  .                  .
    19509                  . 27.743688583374023                  .                  . .                  .                  .
    19874                  . 27.743688583374023                  .                  . .                  .                  .
    20239                  . 31.053213119506836                  .                  . .                  .                  .
    20605                  . 31.053213119506836                  .                  . .                  .                  .
    20970                  . 31.053213119506836                  .                  . .                  .                  .
    21335                  . 31.053213119506836                  .                  . .                  .                  .
    21700                  .  33.52781295776367                  .                  . .                  .                  .
    22066                  .  33.52781295776367                  .                  . .                  .                  .
    15701                  .                  .                  .                  . .                  .                  .
    16066                  .                  .                  .                  . .                  .                  .
    16432                  .                  .                  .                  . .                  .                  .
    14548                  .                  .                  .                  . .                  .                  .
    14914                  .                  .                  .                  . .                  .                  .
    15279                  .                  .                  .                  . .                  .                  .
    15644                  .                  .                  .                  . .                  .                  .
    16009                  .                  .                  .                  . .                  .                  .
    16375                  .                  .                  .                  . .                  .                  .
    16740                  .                  .                  .                  . .                  .                  .
    17105                  .                  .                  .                  . .                  .                  .
    17470                  .                  .                  .                  . .                  .                  .
    17836                  .                  .                  .                  . .                  . 28.618850708007813
    18170                  .                  .                  .                  . .                  .                  .
    18535                  .                  .                  .                  . .                  .                  .
    18900                  .                  .                  .                  . .                  .                  .
    19266                  .                  .                  .                  . .                  .                  .
    19631                  .                  .                  .                  . .                  .                  .
    19996                  .                  .                  .                  . .                  .                  .
    18201                  .                  .                  .                  . .                  . 28.618850708007813
    18566                  .                  .                  .                  . .                  . 32.652652740478516
    18931                  .                  .                  .                  . .                  . 33.990543365478516
    19297                  .                  .                  .                  . .                  . 40.126747131347656
    19662                  .                  .                  .                  . .                  .  36.32431411743164
    20027                  .                  .                  .                  . .                  .  43.20491027832031
    20392                  .                  .                  .                  . .                  .  43.15461349487305
    20758                  .                  .                  .                  . .                  .  43.15461349487305
    21123                  .                  .                  .                  . .                  . 44.070011138916016
    21488                  .                  .                  .                  . .                  .  48.78784942626953
    21853                  .                  .                  .                  . .                  .  50.70918273925781
    22219                  .                  .                  .                  . .                  .  48.39553451538086
    14517                  .                  .                  .                  . .                  .                  .
    14883                  .                  .                  .                  . .                  .                  .
    15248                  .                  .                  .                  . .                  .                  .
    15613                  .                  .                  .                  . .                  .                  .
    15978                  .                  .                  .                  . .                  .                  .
    16344                  .                  .                  .                  . .                  .                  .
    16709                  .                  .                  .                  . .                  .                  .
    17074                  .                  .                  .                  . .                  .                  .
    15798                  .                  .                  .                  . .                  .                  .
    16162                  .                  .                  .                  . .                  .                  .
    16528                  .                  .                  .                  . .                  .                  .
    16893                  .                  .                  .                  . .                  .                  .
    17258                  .                  .                  .                  . .                  .                  .
    17624                  .                  .                  .                  . .                  .                  .
    17989                  .                  .                  .                  . .                  .                  .
    18353                  .                  .                  .                  . .                  .                  .
    18717                  .                  .                  .                  . .                  .                  .
    18808                  .                  .                  .                  . .                  .                  .
    19174                  .                  .                  .                  . .                  .                  .
    19539                  .                  .                  .                  . .                  .                  .
    19904                  .                  .                  .                  . .                  .                  .
    20269                  .                  .                  .                  . .                  .                  .
    20635                  .                  .                  .                  . .                  .                  .
    21000                  .                  .                  .                  . .                  .                  .
    21365                  .                  .                  .                  . .                  .                  .
    end
    format %tdnn/dd/CCYY Dates




  • #2
    Code:
    reshape long CUSIP_ , i(Dates) j(which) string 
    
    gen WHICH = real(which)
    Then you have two versions of the identifier. On the evidence of the data example, they are equivalent.

    Comment


    • #3
      Thank you, Nick Cox .
      Your solution definitely solved the issue!

      Comment

      Working...
      X