Announcement

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

  • help varlist

    Greetings. Don't know how to better name this query ...

    The help entry gives us some indication of how to address variables, including list of variables as in myvar1-myvar6. Now it does note there, that that only "probably" expands to myvar1, myvar2, ..., myvar6.

    Here's the query. When having a humongous list of variables that one wants to e.g.

    Code:
    egen _grandtotal = rowtotal(myvar1-myvar323 myvar4039 myvar5000-5032)
    that don't work, promting a type mismatch r(109) error; but

    Code:
    egen _grandtotal = rowtotal(myvar*)
    does (so commands such as egen aren't completely agnostic in respect to naming conventions/possibilities).

    So I wouldn't be very fond of having to write out all those variables ... Anyone out there that knows one of "those" secret workarounds? Doing it per foreach would just be too simple ;-)

    Cheers!
    Last edited by Stefan Kreisel; 23 Aug 2023, 09:53.

  • #2
    Whoops! That goes to show that writing Statalist queries is faster than checking ones own code. As always Stata works meticulously - the type mismatch r(109) error came from a lone string variable that had been left behind between myvar1 and myvar323.
    Anyways ...

    Comment


    • #3
      That sounds like an error, but in addition

      Code:
       
       myvar5000-5032
      should have been
      Code:
        
       myvar5000-myvar5032

      Comment

      Working...
      X