Announcement

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

  • Obtaining current value of by-group variable

    Within a by-able program, I'd like to use the current value of the by-group variable, assuming the simplest situation of a byable program with just one by-variable. I would have thought this would be stored in some macro, but I didn't find that in the documentation. The best I can come up with is the following, which seems clumsy:
    Code:
    program test, byable
    marksample touse
    levelsof `_byvars' if `touse', local(byval)
    ... now do whatever with `byval'
    end

  • #2
    Your setup isn't entirely clear. The example code yields an error because the option byable must be specified as byable(recall) or byable(onecall). Let's assume you want the former. Assuming further
    Originally posted by Mike Lacy View Post
    the simplest situation of a byable program with just one by-variable
    you could code

    Code:
    program myby, byable(recall)
        local byval = `_byvars'[_byn1()]
        ... now do whatever with `byval'
    end
    This is documented in [P] byable.

    Obviously, the code will fail when more (or less) than one by-variable is specified. It is not clear how you want to handle these cases.
    Last edited by daniel klein; 21 Mar 2025, 02:15.

    Comment


    • #3
      Thanks Daniel. You're right on target. The _byn1() was what I needed and I overlooked its relevance here. I had forgotten to include (recall) in my posting; good to include it to avoid misleading a future reader.

      Comment

      Working...
      X