Announcement

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

  • How to drop singleton observations?

    Dear Stata Users,

    I am using "reghdfe" packages that automatically drops singleton observations. I use the following regression:

    Code:
    reghdfe y x1 x2 x3 x4 , ab(firm year i.state#i.year i.industry#i.year) vce(cluster firm)
    My question is, knowing the fixed effect structure from the above regression, how can I manually drop singleton observation in my data sample?

    Thank you for the help.

  • #2
    Alberto:
    set aside any consideration about the correctness of your approach, you may want to try:
    Code:
    bysort firm (year): drop if _N==1
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you very much for your reply. I followed your step, by I still have some singleton observations that are dropped once I use "reghdfe" packages. Can it be because of "i.state#i.year i.industry#i.year"?

      Comment


      • #4
        If you have missing entries on used variables but nonmissing identifiers, Carlo Lazzaro's code will not capture the singletons. A simple way is to determine the in-sample observations and then drop firms with a single observation. See

        Code:
        help e(sample)

        A more complicated way is the following:

        Code:
        gen nonmissing= !missing(y) & !missing(x1) & !missing(x2) &  !missing(x3) & !missing(x4)
        bys firm: egen count= total(nonmissing)
        drop if count<2
        Last edited by Andrew Musau; 26 Jun 2022, 14:21.

        Comment

        Working...
        X