Announcement

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

  • Drop duplicate quarterly dates

    Hi,

    I am working with a dataset which consisted of monthly obeservations of two variables m1 and m3. I have now converted these montly dates to quarterly dates using
    Code:
     gen tq=qofd(dofm(mdate))
    I then used
    Code:
     bys tq : egen m_m3 = mean(m3)
    and
    Code:
     bys tq : egen m_m1 = mean(m1)
    to generate quarterly means of m1 and m3.

    Now I am left with this
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long(m1 m3) float(mdate tq m_m3 m_m1)
    675257 1010626 469 156 1017618.7 675961.3
    673473 1013138 470 156 1017618.7 675961.3
    671683 1027389 471 157 1052953.6 685409.3
    686539 1061767 472 157 1052953.6 685409.3
    698006 1069705 473 157 1052953.6 685409.3
    689486 1063959 474 158 1081558.4   700371
    698217 1088696 475 158 1081558.4   700371
    713410 1092020 476 158 1081558.4   700371
    733974 1117443 477 159   1113815   741235
    737779 1119119 478 159   1113815   741235
    751952 1104883 479 159   1113815   741235
    end
    format %tm mdate
    format %tq tq
    And the only thing left to do is to drop the duplicate quarterly variables, and of course the corresponding variables of these quarters. That is I want to drop observation 2, 3, 5, 6, 8, 9, ... , 305, 306"

    I have been experimenting with
    Code:
     list tq if mod(_n,2)
    but I only mangages to list every 2nd, 3rd etc, observation.
    Last edited by Nils Rydstedt; 29 Sep 2020, 02:11.

  • #2
    Check out the duplicates command (see help duplicates)

    This will drop all duplicate observation with regard to the variable tq:

    Code:
    duplicates drop tq, force

    Comment


    • #3
      Thank you a lot!!

      Comment

      Working...
      X