Announcement

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

  • Global macro containing all variables except one

    Hi everyone,

    I'm a new user of Stata. My question is hopefully straightforward: I would like to have a global macro in which all my variables would be in except one (called "TOT" ).

    I first tired using levelsof but I did not manage to "remove" the undersired variable from there.

    Any help would be greatly appreciated. Thanks a lot.

  • #2
    levelsof is about distinct values of a single variable, not about the names of one of more variables. One of these may be what you want.

    I illustrate in terms of local macros, which is usually better style, but see help macrolists for more syntax.

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . unab all : *
    
    . di "`all'"
    make price mpg rep78 headroom trunk weight length turn displacement gear_ratio foreign
    
    . local omit mpg
    
    . local all : list all - omit
    
    . di "`all'"
    make price rep78 headroom trunk weight length turn displacement gear_ratio foreign
    
    . levelsof rep78 , local(values)
    1 2 3 4 5
    
    . local omit 3
    
    . local values : list values - omit
    
    . di "`values'"
    1 2 4 5
    .
    Last edited by Nick Cox; 01 May 2020, 11:13.

    Comment


    • #3
      Thanks a lot, it seems to be working.

      Comment

      Working...
      X