Announcement

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

  • if condition "name global variable == " then enter the subroutine

    Hi,

    I am trying to come up with an "if condition" that would allow me to enter parts of the code if the global variable == a certain name, otherwise ignore part of the code. I have tried the following but the syntax is not correct:

    Code:
    global universe "LNASCOMP"
    
    if $universe == "LNASCOMP" { 
     display "Hello, world" }
    I am getting the following output:
    Code:
    . if $universe == "LNASCOMP" {
    LNASCOMP not found
    Please help. Thanks.



  • #2
    When the macro substitution occurs, the result is
    Code:
    if LNASCOMP == "LNASCOMP" {
    and to Stata, this means
    if the variable named LNASCOMP is equal to the string value "LNASCOMP" then . . .
    Stata cannot find any variable named LNASCOMP in your dataset, and so it gives you that error message.

    If you want the compare the string contents of the global macro to a particular string value, then
    Code:
     if "$universe" == "LNASCOMP" {

    Comment


    • #3
      Joseph Coveney hits the nail on the proverbial head. But see also https://www.stata.com/statalist/arch.../msg01258.html

      Comment

      Working...
      X