Announcement

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

  • Data collapse

    Hi


    I have data on a number of lat & lon. Each lat & long combination has daily data on temperature. I want to get the monthly series (by taking the sum of ti) for each lat & long. I want to keep the accuracy of lat & long as given in the data. that do not want to reduce the decimal points during the collapse process.

    How I can do this?

    Thanks
    Attached Files

  • #2
    I think others have already pointed out that the preferred way to show example data is using the -dataex- command. Some of us, myself included, will not download files from people we do not know. So I have not looked at your data; my response is based only on your description of the problem.

    There is no worry that -collapse- will cause loss of precision in this process.
    Code:
    collapse (sum) ti, by(lat lon)
    will preserve the values of lat and lon exactly as they appear in the original data set.

    Comment


    • #3
      ----------------------- copy starting from the next line -----------------------
      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input str10 date double(lon lat t975 t1000) str8 time int year byte(month day) double(x y) float(mdate ti)
      "2011-01-01"  71.8344582 35.16956641 289.6302 291.0283 "19:00:00" 2011  1  1 71.8345 35.1696 612 1.3981
      "2011-01-02"  71.8344582 35.16956641 289.7067 291.0572 "19:00:00" 2011  1  2 71.8345 35.1696 612 1.3505
      "2011-01-03"  71.8344582 35.16956641 289.2128 290.5839 "19:00:00" 2011  1  3 71.8345 35.1696 612 1.3711
      "2011-01-04"  71.8344582 35.16956641 287.8799 289.2345 "19:00:00" 2011  1  4 71.8345 35.1696 612 1.3546
      "2011-01-05"  71.8344582 35.16956641  288.441 289.7883 "19:00:00" 2011  1  5 71.8345 35.1696 612 1.3473
      "2011-01-06"  71.8344582 35.16956641 289.3699 290.7327 "19:00:00" 2011  1  6 71.8345 35.1696 612 1.3628
      "2011-01-07"  71.8344582 35.16956641 287.2682 288.6838 "19:00:00" 2011  1  7 71.8345 35.1696 612 1.4156
      "2011-01-08"  71.8344582 35.16956641 285.7059 287.0998 "19:00:00" 2011  1  8 71.8345 35.1696 612 1.3939
      "2011-01-09"  71.8344582 35.16956641 287.2785 288.6311 "19:00:00" 2011  1  9 71.8345 35.1696 612 1.3526
      "2011-01-10"  71.8344582 35.16956641 288.6528 290.0642 "19:00:00" 2011  1 10 71.8345 35.1696 612 1.4114
      "2011-01-11"  71.8344582 35.16956641 287.9026 289.3234 "19:00:00" 2011  1 11 71.8345 35.1696 612 1.4208
      "2011-01-12"  71.8344582 35.16956641  287.106 288.5195 "19:00:00" 2011  1 12 71.8345 35.1696 612 1.4135
      "2011-01-13"  71.8344582 35.16956641 282.7528 284.1384 "19:00:00" 2011  1 13 71.8345 35.1696 612 1.3856
      "2011-01-14"  71.8344582 35.16956641 281.6968 283.0649 "19:00:00" 2011  1 14 71.8345 35.1696 612 1.3681
      "2011-01-15"  71.8344582 35.16956641 283.0122 284.3606 "19:00:00" 2011  1 15 71.8345 35.1696 612 1.3484
      "2011-01-16"  71.8344582 35.16956641 286.7619 288.1589 "19:00:00" 2011  1 16 71.8345 35.1696 612  1.397
      "2011-01-17"  71.8344582 35.16956641 284.8545 286.2194 "19:00:00" 2011  1 17 71.8345 35.1696 612 1.3649
      "2011-01-18"  71.8344582 35.16956641 284.1818  285.553 "19:00:00" 2011  1 18 71.8345 35.1696 612 1.3712
      "2011-01-19"  71.8344582 35.16956641 288.2395 289.6085 "19:00:00" 2011  1 19 71.8345 35.1696 612  1.369
      "2011-01-20"  71.8344582 35.16956641 286.1481 287.5027 "19:00:00" 2011  1 20 71.8345 35.1696 612 1.3546
      "2011-01-21"  71.8344582 35.16956641 286.1781 287.5906 "19:00:00" 2011  1 21 71.8345 35.1696 612 1.4125
      "2011-01-22"  71.8344582 35.16956641 286.6637 288.0483 "19:00:00" 2011  1 22 71.8345 35.1696 612 1.3846
      "2011-01-23"  71.8344582 35.16956641 285.9838 287.3726 "19:00:00" 2011  1 23 71.8345 35.1696 612 1.3888
      "2011-01-24"  71.8344582 35.16956641 286.3972 287.7693 "19:00:00" 2011  1 24 71.8345 35.1696 612 1.3721
      "2011-01-25"  71.8344582 35.16956641 286.2608 287.5895 "19:00:00" 2011  1 25 71.8345 35.1696 612 1.3287
      "2011-01-26"  71.8344582 35.16956641 286.1822 287.5389 "19:00:00" 2011  1 26 71.8345 35.1696 612 1.3567
      "2011-01-27"  71.8344582 35.16956641 288.9411 290.2915 "19:00:00" 2011  1 27 71.8345 35.1696 612 1.3504
      "2011-01-28"  71.8344582 35.16956641 287.7776  289.126 "19:00:00" 2011  1 28 71.8345 35.1696 612 1.3484
      "2011-01-29"  71.8344582 35.16956641 284.1023 285.4631 "19:00:00" 2011  1 29 71.8345 35.1696 612 1.3608
      "2011-01-30"  71.8344582 35.16956641 287.2847  288.661 "19:00:00" 2011  1 30 71.8345 35.1696 612 1.3763
      "2011-01-31"  71.8344582 35.16956641 289.5434 290.9063 "19:00:00" 2011  1 31 71.8345 35.1696 612 1.3629
      "2011-02-01"  71.8344582 35.16956641 291.4126 292.7962 "19:00:00" 2011  2  1 71.8345 35.1696 613 1.3836
      "2011-02-02"  71.8344582 35.16956641 288.4771 289.8503 "19:00:00" 2011  2  2 71.8345 35.1696 613 1.3732
      "2011-02-03"  71.8344582 35.16956641 287.2796 288.6517 "19:00:00" 2011  2  3 71.8345 35.1696 613 1.3721
      "2011-02-04"  71.8344582 35.16956641  285.119 286.5087 "19:00:00" 2011  2  4 71.8345 35.1696 613 1.3897
      "2011-02-05"  71.8344582 35.16956641 286.0107  287.386 "19:00:00" 2011  2  5 71.8345 35.1696 613 1.3753
      "2011-02-06"  71.8344582 35.16956641 284.1064 285.4775 "19:00:00" 2011  2  6 71.8345 35.1696 613 1.3711
      "2011-02-07"  71.8344582 35.16956641 284.8504 286.2194 "19:00:00" 2011  2  7 71.8345 35.1696 613  1.369
      "2011-02-08"  71.8344582 35.16956641 287.1587 288.5804 "19:00:00" 2011  2  8 71.8345 35.1696 613 1.4217
      "2011-02-09"  71.8344582 35.16956641 286.9789 288.3883 "19:00:00" 2011  2  9 71.8345 35.1696 613 1.4094
      "2011-02-10"  71.8344582 35.16956641 288.8677 290.2657 "19:00:00" 2011  2 10 71.8345 35.1696 613  1.398
      "2011-02-11"  71.8344582 35.16956641 285.9125 287.2734 "19:00:00" 2011  2 11 71.8345 35.1696 613 1.3609
      "2011-02-12"  71.8344582 35.16956641  284.746 286.1461 "19:00:00" 2011  2 12 71.8345 35.1696 613 1.4001
      "2011-02-13"  71.8344582 35.16956641 284.4164 285.7886 "19:00:00" 2011  2 13 71.8345 35.1696 613 1.3722
      "2011-02-14"  71.8344582 35.16956641 284.8555 286.2422 "19:00:00" 2011  2 14 71.8345 35.1696 613 1.3867
      "2011-02-15"  71.8344582 35.16956641 286.6121 287.9987 "19:00:00" 2011  2 15 71.8345 35.1696 613 1.3866
      "2011-02-16"  71.8344582 35.16956641 285.8061 287.1783 "19:00:00" 2011  2 16 71.8345 35.1696 613 1.3722
      "2011-02-17"  71.8344582 35.16956641 285.8578 287.2382 "19:00:00" 2011  2 17 71.8345 35.1696 613 1.3804
      "2011-02-18"  71.8344582 35.16956641 286.7557 288.1702 "19:00:00" 2011  2 18 71.8345 35.1696 613 1.4145
      "2011-02-19"  71.8344582 35.16956641 282.7993 284.1477 "19:00:00" 2011  2 19 71.8345 35.1696 613 1.3484
      "2011-02-20"  71.8344582 35.16956641 286.3517 287.6918 "19:00:00" 2011  2 20 71.8345 35.1696 613 1.3401
      "2011-02-21"  71.8344582 35.16956641 289.4474 290.8154 "19:00:00" 2011  2 21 71.8345 35.1696 613  1.368
      "2011-02-22"  71.8344582 35.16956641 286.8518 288.2302 "19:00:00" 2011  2 22 71.8345 35.1696 613 1.3784
      "2011-02-23"  71.8344582 35.16956641 284.2356 285.6119 "19:00:00" 2011  2 23 71.8345 35.1696 613 1.3763
      "2011-02-24"  71.8344582 35.16956641 284.0248 285.4031 "19:00:00" 2011  2 24 71.8345 35.1696 613 1.3783
      "2011-02-25"  71.8344582 35.16956641   282.48 283.8491 "19:00:00" 2011  2 25 71.8345 35.1696 613 1.3691
      "2011-02-26"  71.8344582 35.16956641 282.5606 283.9369 "19:00:00" 2011  2 26 71.8345 35.1696 613 1.3763
      "2011-02-27"  71.8344582 35.16956641 283.3531 284.7067 "19:00:00" 2011  2 27 71.8345 35.1696 613 1.3536
      "2011-02-28"  71.8344582 35.16956641 282.3808 283.7613 "19:00:00" 2011  2 28 71.8345 35.1696 613 1.3805
      "2011-03-01"  71.8344582 35.16956641 287.1783  288.566 "19:00:00" 2011  3  1 71.8345 35.1696 614 1.3877
      "2011-03-02"  71.8344582 35.16956641 283.2157 284.5641 "19:00:00" 2011  3  2 71.8345 35.1696 614 1.3484
      "2011-03-03"  71.8344582 35.16956641 283.9163 285.2957 "19:00:00" 2011  3  3 71.8345 35.1696 614 1.3794
      "2011-03-04"  71.8344582 35.16956641 283.7634 285.1211 "19:00:00" 2011  3  4 71.8345 35.1696 614 1.3577
      "2011-03-05"  71.8344582 35.16956641 286.0644 287.4139 "19:00:00" 2011  3  5 71.8345 35.1696 614 1.3495
      "2011-03-06"  71.8344582 35.16956641 287.7683 289.1632 "19:00:00" 2011  3  6 71.8345 35.1696 614 1.3949
      "2011-03-07"  71.8344582 35.16956641 287.1566 288.5453 "19:00:00" 2011  3  7 71.8345 35.1696 614 1.3887
      "2011-03-08"  71.8344582 35.16956641 289.4153  290.865 "19:00:00" 2011  3  8 71.8345 35.1696 614 1.4497
      "2011-03-09"  71.8344582 35.16956641 292.2888 293.6972 "19:00:00" 2011  3  9 71.8345 35.1696 614 1.4084
      "2011-03-10"  71.8344582 35.16956641 293.2766 294.7025 "19:00:00" 2011  3 10 71.8345 35.1696 614 1.4259
      "2011-03-11"  71.8344582 35.16956641 293.6858 295.0942 "19:00:00" 2011  3 11 71.8345 35.1696 614 1.4084
      "2011-03-12"  71.8344582 35.16956641 295.4589 296.8941 "19:00:00" 2011  3 12 71.8345 35.1696 614 1.4352
      "2011-03-13"  71.8344582 35.16956641 297.6887 299.0702 "19:00:00" 2011  3 13 71.8345 35.1696 614 1.3815
      "2011-03-14"  71.8344582 35.16956641  299.375  300.712 "19:00:00" 2011  3 14 71.8345 35.1696 614  1.337
      "2011-03-15"  71.8344582 35.16956641 298.9978 300.3762 "19:00:00" 2011  3 15 71.8345 35.1696 614 1.3784
      "2011-03-16"  71.8344582 35.16956641 298.0865 299.5021 "19:00:00" 2011  3 16 71.8345 35.1696 614 1.4156
      "2011-03-17"  71.8344582 35.16956641 294.8627 296.3082 "19:00:00" 2011  3 17 71.8345 35.1696 614 1.4455
      "2011-03-18"  71.8344582 35.16956641 294.7904 296.1791 "19:00:00" 2011  3 18 71.8345 35.1696 614 1.3887
      "2011-03-19"  71.8344582 35.16956641 292.0254 293.4161 "19:00:00" 2011  3 19 71.8345 35.1696 614 1.3907
      "2011-03-20"  71.8344582 35.16956641 292.3705 293.7953 "19:00:00" 2011  3 20 71.8345 35.1696 614 1.4248
      "2011-03-21"  71.8344582 35.16956641 294.7087 296.1502 "19:00:00" 2011  3 21 71.8345 35.1696 614 1.4415
      "2011-03-22"  71.8344582 35.16956641 295.5199 296.9644 "19:00:00" 2011  3 22 71.8345 35.1696 614 1.4445
      "2011-03-23"  71.8344582 35.16956641 296.2948 297.7176 "19:00:00" 2011  3 23 71.8345 35.1696 614 1.4228
      "2011-03-24"  71.8344582 35.16956641 296.6844 298.1857 "19:00:00" 2011  3 24 71.8345 35.1696 614 1.5013
      "2011-03-25"  71.8344582 35.16956641 295.8722 297.3281 "19:00:00" 2011  3 25 71.8345 35.1696 614 1.4559
      "2011-03-26"  71.8344582 35.16956641 295.1644 296.6523 "19:00:00" 2011  3 26 71.8345 35.1696 614 1.4879
      "2011-03-27"  71.8344582 35.16956641  289.932 291.3548 "19:00:00" 2011  3 27 71.8345 35.1696 614 1.4228
      "2011-03-28"  71.8344582 35.16956641 292.5327 293.9255 "19:00:00" 2011  3 28 71.8345 35.1696 614 1.3928
      "2011-03-29"  71.8344582 35.16956641 292.1669 293.5753 "19:00:00" 2011  3 29 71.8345 35.1696 614 1.4084
      "2011-03-30"  71.8344582 35.16956641 291.0964 292.4996 "19:00:00" 2011  3 30 71.8345 35.1696 614 1.4032
      "2011-03-31"  71.8344582 35.16956641 292.7631 294.1983 "19:00:00" 2011  3 31 71.8345 35.1696 614 1.4352
      "2011-04-01"  71.8344582 35.16956641 288.1992 289.5837 "19:00:00" 2011  4  1 71.8345 35.1696 615 1.3845
      "2011-04-02"  71.8344582 35.16956641 290.7048  292.109 "19:00:00" 2011  4  2 71.8345 35.1696 615 1.4042
      "2011-04-03"  71.8344582 35.16956641 291.3992 292.7972 "19:00:00" 2011  4  3 71.8345 35.1696 615  1.398
      
      
      
      end
      format %tm mdate
      ------------------ copy up to and including the previous line ------------------

      Comment


      • #4
        Originally posted by Clyde Schechter View Post
        I think others have already pointed out that the preferred way to show example data is using the -dataex- command. Some of us, myself included, will not download files from people we do not know. So I have not looked at your data; my response is based only on your description of the problem.

        There is no worry that -collapse- will cause loss of precision in this process.
        Code:
        collapse (sum) ti, by(lat lon)
        will preserve the values of lat and lon exactly as they appear in the original data set.
        Thanks


        This gives only three observations; one observation for each lat and long. I want a Monthly time series for each lat and long.

        Comment


        • #5
          Sorry, I missed the part about monthly series in #1.

          Code:
          collapse (sum) ti, by(lon lat mdate)

          Comment


          • #6
            Thanks

            I am using a similar command on another set of data. Where I want to take the mean of pm10. I am getting the following result 0.00000007744. whereas if I calculate the value in Excel, I get it as 0.00000007743685483871.


            collapse (mean) pm10, by(lat lon mdate)

            what I need to change in the above command to get the results as 0.00000007743685483871


            Thanks

            Comment


            • #7
              I am getting the following result 0.00000007744.
              Actually, you probably aren't getting that result. If pm10 is a double in the data before you -collapse- it, then the mean will also be a double after -collapse-. The precision will not be lost. But the default display format will not show you that full precision. Changing nothing in the data itself, if you -format pm10 %20.12e- after the -collapse- you will be able to see that all the significant figures are there. (It will display in scientific notation.) If you don't want to see it in scientificnotation, -format pm10 %21.20f- will show it as 0.00000007743685483871.

              The important point to understand is that in Stata what you see is not necessarily what is in Stata's memory. Stata display results, by default, in ways that are what most users will want to see most of the time: very few people want to see a decimal number with 20 decimal places, of which the final 12 are significant. I don't think anybody believes that 12 significant figures is a realistic representation of any measurement process. And we normally prefer to see a more compact display. But the -format- command gives you control over these things. So suit yourself.

              Comment

              Working...
              X