Announcement

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

  • ds vs display loop

    Hello,


    Can anyone help me identify why:

    Code:
    foreach var of varlist `contvarlist' {
                di "`var'"
                }
    Would produce a shorter variable list than
    Code:
    ds `catvarlist'

    If it's helpful, catvarlist is:
    Code:
       foreach v of var *{
            inspect `v'
            if r(N_unique)<10 {
            local catvarlist `catvarlist' `v'
            }
            }
    Additionally, if there's any info I could/should add, please let me know.

    Thank you!

    -Reese

    v14.2

  • #2
    There can't be an answer in general. There are datasets with no continuous variables on this criterion and datasets with no categorical variables. So, the lengths of each list are labile.

    Note this way to get variables with at most 9 distinct values

    Code:
    . sysuse auto , clear
    (1978 Automobile Data)
    
    . distinct, max(9)
    
    -------------------------------------
                  |     total   distinct
    --------------+----------------------
            rep78 |        69          5
         headroom |        74          8
          foreign |        74          2
    -------------------------------------
    where distinct is


    SJ-15-3 dm0042_2 . . . . . . . . . . . . . . . . Software update for distinct
    (help distinct if installed) . . . . . . N. J. Cox and G. M. Longton
    Q3/15 SJ 15(3):899
    improved table format and display of large numbers of
    observations

    SJ-12-2 dm0042_1 . . . . . . . . . . . . . . . . Software update for distinct
    (help distinct if installed) . . . . . . N. J. Cox and G. M. Longton
    Q2/12 SJ 12(2):352
    options added to restrict output to variables with a minimum
    or maximum of distinct values

    SJ-8-4 dm0042 . . . . . . . . . . . . Speaking Stata: Distinct observations
    (help distinct if installed) . . . . . . N. J. Cox and G. M. Longton
    Q4/08 SJ 8(4):557--568
    shows how to answer questions about distinct observations
    from first principles; provides a convenience command

    Comment


    • #3
      Originally posted by Reese Crispen View Post
      Additionally, if there's any info I could/should add, please let me know.
      How about a reproducible example? Showing the actual output, so we can see the claimed differences, would probably help, too.

      Best
      Daniel

      Comment

      Working...
      X