Announcement

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

  • Separate data

    Dear Stata Users,


    I have a dataset of WINDSPEED (value in the dataset below) for each Lat/Long combination for every month of 2023 starting from Jan till Dec (i.e.,for January the data starts with 90 Lat 0 Long combination and finishes at -90 Lat 359.75 Long combination then the data for February starts and so on.)

    Is it possible to separate the Value variable according to Months for each Lat/Long combination.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(latitude longitude value)
    90     0 7.616347
    90   .25 7.616347
    90    .5 7.616347
    90   .75 7.616347
    90     1 7.616347
    90  1.25 7.616347
    90   1.5 7.616347
    90  1.75 7.616347
    90     2 7.616347
    90  2.25 7.616347
    90   2.5 7.616347
    90  2.75 7.616347
    90     3 7.616347
    90  3.25 7.616347
    90   3.5 7.616347
    90  3.75 7.616347
    90     4 7.616347
    90  4.25 7.616347
    90   4.5 7.616347
    90  4.75 7.616347
    90     5 7.616347
    90  5.25 7.616347
    90   5.5 7.616347
    90  5.75 7.616347
    90     6 7.616347
    90  6.25 7.616347
    90   6.5 7.616347
    90  6.75 7.616347
    90     7 7.616347
    90  7.25 7.616347
    90   7.5 7.616347
    90  7.75 7.616347
    90     8 7.616347
    90  8.25 7.616347
    90   8.5 7.616347
    90  8.75 7.616347
    90     9 7.616347
    90  9.25 7.616347
    90   9.5 7.616347
    90  9.75 7.616347
    90    10 7.616347
    90 10.25 7.616347
    90  10.5 7.616347
    90 10.75 7.616347
    90    11 7.616347
    90 11.25 7.616347
    90  11.5 7.616347
    90 11.75 7.616347
    90    12 7.616347
    90 12.25 7.616347
    90  12.5 7.616347
    90 12.75 7.616347
    90    13 7.616347
    90 13.25 7.616347
    90  13.5 7.616347
    90 13.75 7.616347
    90    14 7.616347
    90 14.25 7.616347
    90  14.5 7.616347
    90 14.75 7.616347
    90    15 7.616347
    90 15.25 7.616347
    90  15.5 7.616347
    90 15.75 7.616347
    90    16 7.616347
    90 16.25 7.616347
    90  16.5 7.616347
    90 16.75 7.616347
    90    17 7.616347
    90 17.25 7.616347
    90  17.5 7.616347
    90 17.75 7.616347
    90    18 7.616347
    90 18.25 7.616347
    90  18.5 7.616347
    90 18.75 7.616347
    90    19 7.616347
    90 19.25 7.616347
    90  19.5 7.616347
    90 19.75 7.616347
    90    20 7.616347
    90 20.25 7.616347
    90  20.5 7.616347
    90 20.75 7.616347
    90    21 7.616347
    90 21.25 7.616347
    90  21.5 7.616347
    90 21.75 7.616347
    90    22 7.616347
    90 22.25 7.616347
    90  22.5 7.616347
    90 22.75 7.616347
    90    23 7.616347
    90 23.25 7.616347
    90  23.5 7.616347
    90 23.75 7.616347
    90    24 7.616347
    90 24.25 7.616347
    90  24.5 7.616347
    90 24.75 7.616347
    end

  • #2
    Saptorshee:
    I would first crate a variable that group lat and long:
    Code:
     egen wanted=group( latitude longitude)
    Then you can -sort- according to months.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      In what you show there is one and only one windspeed value for each (latitude, longitude) pair, so you would end up with as many variables as observations. It's not clear what that would achieve.

      On a different level: latitude 90 N is the North Pole and latitude 90 S is the South Pole and at either pole longitude is indeterminate.

      So, I suppose it makes sense that windspeed is reported the same for different longitudes.
      Last edited by Nick Cox; 25 Jul 2024, 04:34.

      Comment


      • #4
        Carlo Lazzaro Thank you very much, but could you let me know after sorting the new variable ' wanted'. How can I separate the data and create new variables ' value_jan, value_feb,...., value_dec' for each lat/long combination.


        Regards

        Comment


        • #5
          You might start with something like

          Code:
          gen byte new_month = (latitude == 90 & longitude == 0)
          gen cumul_month = sum(new_month)
          and go from there. The details would depend on what other variables you have to denote year etc.
          Last edited by Hemanshu Kumar; 25 Jul 2024, 04:13.

          Comment


          • #6
            Saptorshee:
            things would be easier is you share an example that includes your -month- variable. Thanks.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Nick Cox Thank you for your reply, my post might not have been clear. The data is for each Lat/Long combination monthly average. Since the data was from GRIB file (fig contains data for year 2023) converted to CSV, data is sorted for month one after another in the column value. I want to seperate the value according to month for each LAT/LONG combination.

              Regards
              Attached Files

              Comment


              • #8
                Hemanshu Kumar Thank you very much. This works perfectly.


                Regards

                Comment


                • #9
                  Hemanshu Kumar by any chance is there a way to rearrange the COLUMN "value" according to "latitude", "longitude" and "cumul_month_1", "cumul_month_2","cumul_month_3",....,"cumul_month_ 12"


                  Regards

                  Comment


                  • #10
                    Could you explain what you mean, perhaps showing a small example of what your final dataset should look like?

                    Comment


                    • #11
                      Sorry for the confusion.... before you had suggested the way to use the to seperate the data according to months. Is it somehow possible to break the "value" column according to each LAT/LONG combination and "cumul_month"




                      Code:
                      * Example generated by -dataex-. For more info, type help dataex
                      clear
                      input float(latitude longitude value) byte new_month float cumul_month
                      90     0 7.616347 1 1
                      90   .25 7.616347 0 1
                      90    .5 7.616347 0 1
                      90   .75 7.616347 0 1
                      90     1 7.616347 0 1
                      90  1.25 7.616347 0 1
                      90   1.5 7.616347 0 1
                      90  1.75 7.616347 0 1
                      90     2 7.616347 0 1
                      90  2.25 7.616347 0 1
                      90   2.5 7.616347 0 1
                      90  2.75 7.616347 0 1
                      90     3 7.616347 0 1
                      90  3.25 7.616347 0 1
                      90   3.5 7.616347 0 1
                      90  3.75 7.616347 0 1
                      90     4 7.616347 0 1
                      90  4.25 7.616347 0 1
                      90   4.5 7.616347 0 1
                      90  4.75 7.616347 0 1
                      90     5 7.616347 0 1
                      90  5.25 7.616347 0 1
                      90   5.5 7.616347 0 1
                      90  5.75 7.616347 0 1
                      90     6 7.616347 0 1
                      90  6.25 7.616347 0 1
                      90   6.5 7.616347 0 1
                      90  6.75 7.616347 0 1
                      90     7 7.616347 0 1
                      90  7.25 7.616347 0 1
                      90   7.5 7.616347 0 1
                      90  7.75 7.616347 0 1
                      90     8 7.616347 0 1
                      90  8.25 7.616347 0 1
                      90   8.5 7.616347 0 1
                      90  8.75 7.616347 0 1
                      90     9 7.616347 0 1
                      90  9.25 7.616347 0 1
                      90   9.5 7.616347 0 1
                      90  9.75 7.616347 0 1
                      90    10 7.616347 0 1
                      90 10.25 7.616347 0 1
                      90  10.5 7.616347 0 1
                      90 10.75 7.616347 0 1
                      90    11 7.616347 0 1
                      90 11.25 7.616347 0 1
                      90  11.5 7.616347 0 1
                      90 11.75 7.616347 0 1
                      90    12 7.616347 0 1
                      90 12.25 7.616347 0 1
                      90  12.5 7.616347 0 1
                      90 12.75 7.616347 0 1
                      90    13 7.616347 0 1
                      90 13.25 7.616347 0 1
                      90  13.5 7.616347 0 1
                      90 13.75 7.616347 0 1
                      90    14 7.616347 0 1
                      90 14.25 7.616347 0 1
                      90  14.5 7.616347 0 1
                      90 14.75 7.616347 0 1
                      90    15 7.616347 0 1
                      90 15.25 7.616347 0 1
                      90  15.5 7.616347 0 1
                      90 15.75 7.616347 0 1
                      90    16 7.616347 0 1
                      90 16.25 7.616347 0 1
                      90  16.5 7.616347 0 1
                      90 16.75 7.616347 0 1
                      90    17 7.616347 0 1
                      90 17.25 7.616347 0 1
                      90  17.5 7.616347 0 1
                      90 17.75 7.616347 0 1
                      90    18 7.616347 0 1
                      90 18.25 7.616347 0 1
                      90  18.5 7.616347 0 1
                      90 18.75 7.616347 0 1
                      90    19 7.616347 0 1
                      90 19.25 7.616347 0 1
                      90  19.5 7.616347 0 1
                      90 19.75 7.616347 0 1
                      90    20 7.616347 0 1
                      90 20.25 7.616347 0 1
                      90  20.5 7.616347 0 1
                      90 20.75 7.616347 0 1
                      90    21 7.616347 0 1
                      90 21.25 7.616347 0 1
                      90  21.5 7.616347 0 1
                      90 21.75 7.616347 0 1
                      90    22 7.616347 0 1
                      90 22.25 7.616347 0 1
                      90  22.5 7.616347 0 1
                      90 22.75 7.616347 0 1
                      90    23 7.616347 0 1
                      90 23.25 7.616347 0 1
                      90  23.5 7.616347 0 1
                      90 23.75 7.616347 0 1
                      90    24 7.616347 0 1
                      90 24.25 7.616347 0 1
                      90  24.5 7.616347 0 1
                      90 24.75 7.616347 0 1
                      end

                      Comment


                      • #12
                        Code:
                        help separate

                        Comment


                        • #13
                          What you are requesting in #11, if I am understanding it correctly, would create millions of new variables, and would exceed Stata's limits on the number of variables. I am also quite certain it is entirely unnecessary. Could you tell us the broader problem you are trying to solve, so that better solutions can be found?

                          Note:
                          1. See XY problem
                          2. It is best not to address your question only to me or any specific individual. Others may well be able to answer your questions better and sooner.
                          Last edited by Hemanshu Kumar; 28 Jul 2024, 11:58.

                          Comment

                          Working...
                          X