Announcement

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

  • Can I specify an if/then statement in power_cmd_init?

    Hi All,

    I am writing a power command using power_usermethod. I would like to have the power_cmd_name_init program change the title, depending on whether an option was specified in the power_cmd_name program. Something like this completely contrived example:

    Code:
    capture program drop power_cmd_whatever_init
    program power_cmd_whatever_init, sclass
            version 11
           if "`level'" == "" {
               sreturn local pss_title " for a test of upper level"
         }
        else {
           sreturn local pss_title " for a test of lower level"
        }
    The local "`level'" would be in the power_usermethod command. I am not sure if I can use a passthrough, or how else to do this. The help file does not discuss this issue.

    Thanks in advance!

    Ariel
    Last edited by Ariel Linden; 30 May 2025, 17:30.

  • #2
    Hi All,

    I want to thank Kerry Kammire at StataCorp for providing the answer to this problem.

    The option "level" is an option in the evaluator program "power_cmd_whatever". This option is passed to the _init program where it is also evaluated:

    Code:
    capture program drop power_cmd_whatever_init
    program power_cmd_whatever_init, sclass
       version 11
       syntax, [level] *
    
       if "`level'" == "" {
          sreturn local pss_title " for a test of upper level"
       }
       else {
          sreturn local pss_title " for a test of lower level"
       }
    end

    Comment

    Working...
    X