Announcement

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

  • how to forcing mrap to dispaly only values with certain frequencies

    I wonder if mrap provides any options such that the frequency table displays only values with top 10 frequencies.

    mrtab ICD10s AA AB AC AD AE AF1 AF2 AF3 AF4 AF5 AF6 AF7 AF8 AF9 AG AH AI AJ AK AL AM AN AO AP AQ AR AS AT AU AV AW AX AY AZ BA BB, ///
    title(ICD10s) include poly nonames width(18) ///
    by(AttendedFRP_new) column mtest(bonferroni) descending

  • #2
    I don't know anything about mrap (where to be found? or an illusion stemming from careless typing?)and I've not used mrtab (Stata Journal / SSC) much but such an option would be documented.

    groups from the Stata Journal can definitely do this for you. Paper at st0496 but install from st0496_1.
    Code:
    . search st0496, entry
    
    Search of official help files, FAQs, Examples, and Stata Journals
    
    SJ-18-1 st0496_1  . . . . . . . . . . . . . . . . . Software update for groups
            (help groups if installed)  . . . . . . . . . . . . . . . .  N. J. Cox
            Q1/18   SJ 18(1):291
            groups exited with an error message if weights were specified;
            this has been corrected
    
    SJ-17-3 st0496  . . . . .  Speaking Stata: Tables as lists: The groups command
            (help groups if installed)  . . . . . . . . . . . . . . . .  N. J. Cox
            Q3/17   SJ 17(3):760--773
            presents command for listing group frequencies and percents and
            cumulations thereof; for various subsetting and ordering by
            frequencies, percents, and so on; for reordering of columns;
            and for saving tabulated data to new datasets

    Comment


    • #3
      Thanks but I wonder how groups can be combined with mrtab! All I need is that the below code only displays values with the highest frequencies (top 10).

      mrtab ICD10s AA AB AC AD AE AF1 AF2 AF3 AF4 AF5 AF6 AF7 AF8 AF9 AG AH AI AJ AK AL AM AN AO AP AQ AR AS AT AU AV AW AX AY AZ BA BB, ///
      title(ICD10s) include poly nonames width(18) ///
      by(AttendedFRP_new) column mtest(bonferroni) descending


      Comment


      • #4
        The help for groups explains that you can save whatever is displayed to a new dataset. Here is an example and I chose the top 5 but the principle is the same.


        Code:
        . webuse nlswork
        (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
        
        
        . groups collgrad-south
        
          +--------------------------------------------------------+
          | collgrad   not_smsa   c_city   south   Freq.   Percent |
          |--------------------------------------------------------|
          |        0          0        0       0    5742     20.13 |
          |        0          0        0       1    2527      8.86 |
          |        0          0        1       0    4941     17.32 |
          |        0          0        1       1    3455     12.11 |
          |        0          1        0       0    3086     10.82 |
          |--------------------------------------------------------|
          |        0          1        0       1    3982     13.96 |
          |        1          0        0       0    1412      4.95 |
          |        1          0        0       1     598      2.10 |
          |        1          0        1       0    1096      3.84 |
          |        1          0        1       1     698      2.45 |
          |--------------------------------------------------------|
          |        1          1        0       0     566      1.98 |
          |        1          1        0       1     423      1.48 |
          +--------------------------------------------------------+
        
        . groups collgrad-south, select(5) order(high)
        
          +--------------------------------------------------------+
          | collgrad   not_smsa   c_city   south   Freq.   Percent |
          |--------------------------------------------------------|
          |        0          0        0       0    5742     20.13 |
          |        0          0        1       0    4941     17.32 |
          |        0          1        0       1    3982     13.96 |
          |        0          0        1       1    3455     12.11 |
          |        0          1        0       0    3086     10.82 |
          +--------------------------------------------------------+
        
        . groups collgrad-south, select(5) order(high) saving(subset)
        
          +--------------------------------------------------------+
          | collgrad   not_smsa   c_city   south   Freq.   Percent |
          |--------------------------------------------------------|
          |        0          0        0       0    5742     20.13 |
          |        0          0        1       0    4941     17.32 |
          |        0          1        0       1    3982     13.96 |
          |        0          0        1       1    3455     12.11 |
          |        0          1        0       0    3086     10.82 |
          +--------------------------------------------------------+
        
        file subset.dta saved
        
        . use subset, clear
        (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
        
        . l
        
             +---------------------------------------------------------+
             | collgrad   not_smsa   c_city   south   _freq   _percent |
             |---------------------------------------------------------|
          1. |        0          0        0       0    5742      20.13 |
          2. |        0          0        1       0    4941      17.32 |
          3. |        0          1        0       1    3982      13.96 |
          4. |        0          0        1       1    3455      12.11 |
          5. |        0          1        0       0    3086      10.82 |
             +---------------------------------------------------------+
        But you don't need that. Basic technique with by: will get you the subset you want directly. See e.g. https://journals.sagepub.com/doi/abs...867X0200200106

        Code:
         
        . webuse nlswork
        (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
        
        . bysort collgrad-south: gen freq = _N
        
        . egen tag = tag(collgrad-south)
        
        
        . gsort  -tag -freq
        
        . l collgrad-south freq in 1/5
        
             +---------------------------------------------+
             | collgrad   not_smsa   c_city   south   freq |
             |---------------------------------------------|
          1. |        0          0        0       0   5742 |
          2. |        0          0        1       0   4941 |
          3. |        0          1        0       1   3982 |
          4. |        0          0        1       1   3455 |
          5. |        0          1        0       0   3086 |
             +---------------------------------------------+
        So either you've now got what you really want, or you call up mrtab with the first so many observations (using an in qualifier) and the frequencies as frequency weights.

        Comment

        Working...
        X