Announcement

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

  • display data format

    I used the -distinct- command to get the total number of observations and the unique values. How can I tell stata to display the total number of observations without approximations (e+07)?

    Code:
    . distinct mreg_res uf_res mun_res bai_res dtnasc cnes mun_obit bai_obit
    
              |        Observations
              |      total   distinct
    ----------+----------------------
     mreg_res |   1.92e+07          5
       uf_res |   1.92e+07         27
      mun_res |   1.92e+07       5646
      bai_res |    6024887       4502
       dtnasc |   1.87e+07      46195
         cnes |    9749227      25486
     mun_obit |   1.92e+07       5639
     bai_obit |     664840       3232

  • #2
    Code:
    . which distinct
    command distinct not found as either built-in or ado-file
    r(111);
    If you mean http://www.stata-journal.com/sjpdf.h...iclenum=dm0042
    then the syntax is clear:
    distinct varlist if in, missing abbrev(#) joint
    which means that there is no control for formatting.

    Why do you need the first column at all?
    Summarize should report the same, and it reserves enough space in the column for the max 2bln obs that Stata allows, so you should be fine with that.

    Sergiy

    Comment


    • #3
      distinct is from the Stata Journal, as you are asked to explain. (FAQ Advice: Explain where user-written programs you refer to come from.)

      The default display formats need revisiting. For now, I suggest this:

      1. Open up distinct.ado in your favourite text editor.

      2. Change the program name to distinct2, or some such new name

      3. Add your name to the opening comments as responsible for this new version.

      4. In this code block

      Code:
       
                      di
                      di as txt _col(`abbp3') "{c |}        Observations"
                      di as txt _col(`abbp3') "{c |}      total   distinct"
                      di as txt "{hline `abbp2'}{c +}{hline 22}"
      
                      foreach v of local varlist {
                              tempvar touse vals
                              mark `touse' `if' `in'
                              // markout separately for each variable in varlist
                              if "`missing'" == "" markout `touse' `v', strok 
                              bys `touse' `v' : gen byte `vals' = (_n == 1) * `touse'
                              su `vals' if `touse', meanonly
                              if r(sum) >= `minimum' & r(sum) <= `maximum' { 
                                      di " " as txt %`abbrev's abbrev("`v'", `abbrev') ///
                                      " {c |}  " as res %9.0g r(N) "  " %9.0g r(sum)
                              } 
                              drop `touse' `vals'
                      }
      edit the formats %9.0g to something bigger and edit the display statements at the top adding more space correspondingly. For example, if you change the formats to %13.0g, then you need to add 4 or 8 spaces in the other statements.

      5. Now save the file as distinct2.ado, or whatever.

      6. Each revision you make to distinct2, remember to flush the program from memory with (e.g.) discard

      Comment

      Working...
      X