Announcement

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

  • Filtering data using several criteria

    Dear all,

    I have a coding question. In the data structure below I have the name of the firm, the class of asset (common or preferred stock) and when the class series started (date variable). Sometimes firm names appear more than one time since they may have 2 or more classes of assets containing different starting dates. Some firms have only one asset class. In these cases I will keep whatever class is available e.g either PN or ON. But for firms with multiple classes, I want to keep ON. If there is more than one ON series available to a firm, I want to keep the one with the oldest starting date. If no ON is available, I want to keep PN. If multiple PNs are available, I want the oldest and so on. I am stuck trying to code this. Any clues?

    Click image for larger version

Name:	data.jpg
Views:	1
Size:	101.4 KB
ID:	1450047
    Last edited by Rodrigo Saurin; 21 Jun 2018, 08:45.

  • #2
    Rodrigo:
    sometimes advised fixes come out from trial and error process (this is my experience, at any rate) ; unfortunately, screenshots does not allow interested listers to experiment with your data.
    Please post and excerpt/example of your dataset via -dataex-. Thanks.
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      Properly sorting then keeping the first obs is what you need to do.
      Code:
      gsort name class -seriessstartdate
      bys name: keep if _n==1

      Comment


      • #4
        Dear Carlo Lazzaro sorry for that, you are completely right about the trial and error.

        Dear Romalpa, that was genious!!! have never heard of gsort before ... seems to have worked exactly as I wanted. Many thanks!!

        Comment

        Working...
        X