Announcement

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

  • Keeping specific values from a tab

    Dear Statalist, I am wondering if it is possible to know automatically the value for the 5 minus the highest and 5 plus the lowest values on a variable. As you can see at the end, I can do this with the fre table, when the values I am interested are -.1490809 and .0326344 respectively. I need those values to list several other variables only for those range of values
    Code:
    list c1 x1 if (c1<=-.1490809  | c1>=.0326344)
    However, these values will be changing. I was trying with the "tab" command to use the position in the matrix, but this can only be done for the first 5 values, but not for the last 5 values since the values (depending on the conditioning) will change and could report 20 or 200 different values. And unfortunately, the tab, sort option only sort for frequencies and not for values.
    Is there any way to keep the specific values I need (similar to a local macro) to use it in the "list" command?

    Thanks in advance.

    Code:
     xttab c1 if year==2010 & c2==1
    
                      Overall             Between            Within
           c1 |    Freq.  Percent      Freq.  Percent        Percent
    ----------+-----------------------------------------------------
     -.299033 |       1      6.25         1      7.14         100.00
     -.261712 |       1      6.25         1      7.14         100.00
    -.1875746 |       1      6.25         1      7.14         100.00
    -.1848576 |       1      6.25         1      7.14         100.00
    -.1490809 |       1      6.25         1      7.14         100.00
    -.1248866 |       1      6.25         1      7.14          33.33
    -.1118712 |       1      6.25         1      7.14         100.00
    -.0203138 |       2     12.50         2     14.29         100.00
     .0326344 |       2     12.50         1      7.14          66.67
      .040889 |       1      6.25         1      7.14         100.00
     .0757612 |       2     12.50         2     14.29         100.00
     .1047588 |       1      6.25         1      7.14         100.00
     1.237074 |       1      6.25         1      7.14         100.00
    ----------+-----------------------------------------------------
        Total |      16    100.00        15    107.14          93.33
                                    (n = 14)
    
    . di r(results)[5,1]
    -.14908086
    Code:
    ---------------------------------------------------------------
                      |      Freq.    Percent      Valid       Cum.
    ------------------+--------------------------------------------
    Valid   -.299033  |          1       4.00       6.25       6.25
            -.261712  |          1       4.00       6.25      12.50
            -.1875746 |          1       4.00       6.25      18.75
            -.1848576 |          1       4.00       6.25      25.00
            -.1490809 |          1       4.00       6.25      31.25
            :         |          :          :          :          :
            .0326344  |          2       8.00      12.50      68.75
            .040889   |          1       4.00       6.25      75.00
            .0757612  |          2       8.00      12.50      87.50
            .1047588  |          1       4.00       6.25      93.75
            1.237074  |          1       4.00       6.25     100.00
            Total     |         16      64.00     100.00           
    Missing .         |          9      36.00                      
    Total             |         25     100.00                      
    ---------------------------------------------------------------

  • #2
    See extremes (SSC). and groups (Stata Journal)


    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . extremes mpg
    
      +------------+
      | obs:   mpg |
      |------------|
      |  26.    12 |
      |  27.    12 |
      |  11.    14 |
      |  12.    14 |
      |  28.    14 |
      +------------+
    
      +------------+
      |  68.    31 |
      |  43.    34 |
      |  57.    35 |
      |  66.    35 |
      |  71.    41 |
      +------------+
    
    note: 6 values of 14
    
    . extremes mpg make
    
      +--------------------------------+
      | obs:   mpg   make              |
      |--------------------------------|
      |  26.    12   Linc. Continental |
      |  27.    12   Linc. Mark V      |
      |  11.    14   Cad. Deville      |
      |  12.    14   Cad. Eldorado     |
      |  28.    14   Linc. Versailles  |
      +--------------------------------+
    
      +-----------------------------+
      |  68.    31   Toyota Corolla |
      |  43.    34   Plym. Champ    |
      |  57.    35   Datsun 210     |
      |  66.    35   Subaru         |
      |  71.    41   VW Diesel      |
      +-----------------------------+
    
    note: 6 values of 14
    
    . groups mpg , select(5)
    
      +-------------------------------+
      | mpg   Freq.   Percent     %<= |
      |-------------------------------|
      |  12       2      2.70    2.70 |
      |  14       6      8.11   10.81 |
      |  15       2      2.70   13.51 |
      |  16       4      5.41   18.92 |
      |  17       4      5.41   24.32 |
      +-------------------------------+
    
    
    
    . groups mpg , select(-5)
    
      +--------------------------------+
      | mpg   Freq.   Percent      %<= |
      |--------------------------------|
      |  30       2      2.70    93.24 |
      |  31       1      1.35    94.59 |
      |  34       1      1.35    95.95 |
      |  35       2      2.70    98.65 |
      |  41       1      1.35   100.00 |
      +--------------------------------+
    Last edited by Nick Cox; 02 Dec 2020, 08:51.

    Comment


    • #3
      Dear Nick, thanks for your help; "extremes" does perfectly what I was looking for. However, since I also need to put several of these tables in a document, I realized that using asdoc with extremes, even though it worked, the column of observations is exported to the Word document and the option "noobs" does not work.
      Is there any way of automatically store those specific two values from "extremes" or any other command that allow me to use it with "list" in order to export the tables to the document?

      Comment


      • #4
        Doris Rivera , if you want help with asdoc, you may like to start a new topic with appropriate title. For reference, asdoc is from SSC
        Code:
        ssc install asdoc
        Further details on asdoc can be found here https://fintechprofessor.com/2018/01/31/asdoc/
        Regards
        --------------------------------------------------
        Attaullah Shah, PhD.
        Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
        FinTechProfessor.com
        https://asdocx.com
        Check out my asdoc program, which sends outputs to MS Word.
        For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

        Comment


        • #5
          I did not see #3 until today, but sorry, I have no idea what "does not work" means here and in any case it appears to be referring to your use of asdoc.

          extremes is essentially an exploratory command and leaves nothing in memory itself.

          Comment

          Working...
          X