Announcement

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

  • How to delete the observations acording to percent generated by tabulate command

    Hi all,I want to delete the observations if the Percent of rep78 <40.00,any tips?

    Similarly, I also want to know hpw to delete the observations if the Freq. of rep78 <30.

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    Code:
    . tab rep78
    Repair
    Record 1978 Freq. Percent Cum.
    1 2 2.90 2.90
    2 8 11.59 14.49
    3 30 43.48 57.97
    4 18 26.09 84.06
    5 11 15.94 100.00
    Total 69 100.00
    Last edited by Qiguo Lian; 19 Oct 2018, 00:40.

  • #2
    This should help. Note that the existence of missings should be considered one way or another.


    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . bysort rep78 : gen count = _N
    
    . count if rep78 < .
      69
    
    . gen percent = 100 * count / r(N)
    
    . tabdisp rep78, c(count percent)
    
    ----------------------------------
    Repair    |
    Record    |
    1978      |      count     percent
    ----------+-----------------------
            1 |          2    2.898551
            2 |          8     11.5942
            3 |         30    43.47826
            4 |         18    26.08696
            5 |         11    15.94203
            . |          5    7.246377
    ----------------------------------
    Notice that you can do things like this

    Code:
    bysort rep78 : drop if _N < 30
    Again, watch out for missings.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      This should help. Note that the existence of missings should be considered one way or another.


      Code:
      . sysuse auto, clear
      (1978 Automobile Data)
      
      . bysort rep78 : gen count = _N
      
      . count if rep78 < .
      69
      
      . gen percent = 100 * count / r(N)
      
      . tabdisp rep78, c(count percent)
      
      ----------------------------------
      Repair |
      Record |
      1978 | count percent
      ----------+-----------------------
      1 | 2 2.898551
      2 | 8 11.5942
      3 | 30 43.47826
      4 | 18 26.08696
      5 | 11 15.94203
      . | 5 7.246377
      ----------------------------------
      Notice that you can do things like this

      Code:
      bysort rep78 : drop if _N < 30
      Again, watch out for missings.
      Thanks, Nick.

      Comment

      Working...
      X