Announcement

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

  • Keeping only row observations in which the value of one variable is equal with another variable

    Hello,

    I am new to the forum and am not quite yet familiar with how asking questions works around here, nevertheless hope someone can help with this issue.

    I have a dataset which includes information regarding bonds such as issuance date, delivery date and other characteristics. I am trying to find a way to keep only row observations in which, say for example, a bond was issued on the 25th of May and it was also delivered to a company on the 25th of May. For example if I have the following dataset:


    Bond ID Issue_Date Delivery_date Yield
    1 05/May/2005 09/May/2005 7%
    2 05/May/2005 05/May/2005 10%
    3 07/May/2005 07/May/2005 8%
    4 07/May/2005 10/May/2005 5%

    After using the correct code, I'd want my dataset to look like:

    Bond ID Issue_Date Delivery_date Yield
    2 05/May/2005 05/May/2005 10%
    3 07/May/2005 07/May/2005 8%

    Essentially I'd want to drop each row observation where the issue date and delivery date do not match.

    Thank you,

    Viktor


  • #2

    Code:
    drop if  Issue_Date != Delivery_date

    EDIT: Rich Goldstein is right in #3. I just copied and pasted too much.
    Last edited by Nick Cox; 12 May 2022, 07:50.

    Comment


    • #3
      alternatively
      Code:
      keep if Issue_Date == Delivery_date
      but, if I understand #1, ID should not be included in #2

      Comment


      • #4
        Thank you both for the help, it worked!

        Comment

        Working...
        X