Announcement

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

  • Count and label copy

    I have a data set in which many variables have few cases, Is there a way to create indices using count or _N so that it is easy to delete these variables?
    Also, when I collapse these variables by country, the new variables X1 - X100 are all labelled mean(X*). Is there a way to copy the labels to the collapsed data set?

    Thanks for any help.

  • #2
    I have a data set in which many variables have few cases, Is there a way to create indices using count or _N so that it is easy to delete these variables?
    You want IIUC to count missing values. misstable summarize (official command) will do it for you as will missings report (Stata Journal)

    Code:
    SJ-20-4 dm0085_2 . . . . . . . . . . . . . . . . Software update for missings
    (help missings if installed) . . . . . . . . . . . . . . . N. J. Cox
    Q4/20 SJ 20(4):1028--1030
    sorting has been extended for missings report
    
    SJ-17-3 dm0085_1 . . . . . . . . . . . . . . . . Software update for missings
    (help missings if installed) . . . . . . . . . . . . . . . N. J. Cox
    Q3/17 SJ 17(3):779
    identify() and sort options have been added
    
    SJ-15-4 dm0085 Speaking Stata: A set of utilities for managing missing values
    (help missings if installed) . . . . . . . . . . . . . . . N. J. Cox
    Q4/15 SJ 15(4):1174--1185
    provides command, missings, as a replacement for, and extension
    of, previous commands nmissing and dropmiss
    Otherwise you have the right to bear arms, but Stata does not give you a gun. You have to take responsibility. Suppose you want to drop all variables as a matter of caprice (say, researcher's personal judgment) if the number of missing values is 42 or greater. Code sketch (not tested):

    Code:
    foreach v of var * {
          quietly count if missing(`v')
          if r(N) >= 42 local droplist `droplist' `v'
    }
    
    if "`droplist'" != "" drop `droplist'
    Also, when I collapse these variables by country, the new variables X1 - X100 are all labelled mean(X*). Is there a way to copy the labels to the collapsed data set?
    FAQ: Keeping the same variable with collapse | Stata is an FAQ on precisely this question from 2003.
    Last edited by Nick Cox; 31 Jan 2024, 09:29.

    Comment

    Working...
    X