Announcement

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

  • Long form data

    Hi

    I have data in Stata

    I want to convert this into long formate, please

    clear
    input LATNUM LONGNUM d2021_02 d2021_03 d2021_04 d2021_05
    36.44991823 72.57155787 99999 99999 99999 99999
    35.89191425 71.72687311 99999 99999 99999 99999
    35.16956641 71.8344582 99999 99999 68420.41716 94735.90842
    end


    Thanks

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(LATNUM LONGNUM d2021_02 d2021_03 d2021_04 d2021_05)
    36.449917 72.571556 99999 99999     99999    99999
    35.891914 71.726875 99999 99999     99999    99999
    35.169567  71.83446 99999 99999 68420.414 94735.91
    end
    
    reshape long d2021, i(LAT LONG) j(which) string
    destring which, ignore(_) replace
    Res.:

    Code:
    . l, sep(0)
    
         +----------------------------------------+
         |   LATNUM    LONGNUM   which      d2021 |
         |----------------------------------------|
      1. | 35.16957   71.83446       2      99999 |
      2. | 35.16957   71.83446       3      99999 |
      3. | 35.16957   71.83446       4   68420.41 |
      4. | 35.16957   71.83446       5   94735.91 |
      5. | 35.89191   71.72688       2      99999 |
      6. | 35.89191   71.72688       3      99999 |
      7. | 35.89191   71.72688       4      99999 |
      8. | 35.89191   71.72688       5      99999 |
      9. | 36.44992   72.57156       2      99999 |
     10. | 36.44992   72.57156       3      99999 |
     11. | 36.44992   72.57156       4      99999 |
     12. | 36.44992   72.57156       5      99999 |
         +----------------------------------------+

    Comment


    • #3
      thanks, I want the column of the year as well, please


      here

      . l, sep(0) +----------------------------------------+ | LATNUM LONGNUM which d2021 | |----------------------------------------| 1. | 35.16957 71.83446 2 99999 | 2. | 35.16957 71.83446 3 99999 | 3. | 35.16957 71.83446 4 68420.41 | 4. | 35.16957 71.83446 5 94735.91 | 5. | 35.89191 71.72688 2 99999 | 6. | 35.89191 71.72688 3 99999 | 7. | 35.89191 71.72688 4 99999 | 8. | 35.89191 71.72688 5 99999 | 9. | 36.44992 72.57156 2 99999 | 10. | 36.44992 72.57156 3 99999 | 11. | 36.44992 72.57156 4 99999 | 12. | 36.44992 72.57156 5 99999 | +----------------------------------------+

      Comment


      • #4
        @Andrew Musau

        how I can get the year information please while converting the from wide to long please


        Comment


        • #5
          Provide an adequate data example with multiple years (at least two). Use dataex.

          Comment

          Working...
          X