Announcement

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

  • How to use abbreviation (like asterisk) for multiple variables in "if" condition of "list" command?

    Dear Statalists,
    I got a tiny problem which trying to filter some qualified subjects from a dataset. I have around 30 variables of which names are all like: h_1_all, h_4_all, h_12_all... The only difference between the names is the number in the middle which is not continuous. And there is also a variable named "id". I'd like to list all "id" of which any of the h_*_all variables has a missing value. But the command like below is not working:
    list id h_*_all if h_*_all==., N
    The result shows h_ ambiguous abbreviation.
    What should I do to solve this issue? Thank you very much!
    Ying

  • #2
    The -if- statement does not allow abbreviations in this way. A work around is to use -egen rowmiss- to count the number of missing values across the variables and list if they are greater than 0.

    Code:
    egen num_miss=rowmiss(h_*_all)
    list id h_*_all if num_miss>0, N
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment

    Working...
    X