Announcement

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

  • IF statement based on string contents of a scalar

    I am trying to write a program, that has option flist(string), where flist can take words such ri rm etc. Now suppose the user specifies flist(ri). How can I supply this flist macro to mata function and see there whether the user has specified ri or rm. I tried the following inside the mata function, but it returned the following error.
    Code:
    flist="ri"
    if(flist="ri") "option is ri" ; ;
     <istmt>:  3250  type mismatch
    my question is how to evaluate a string scalar through if statement.

  • #2
    In Stata, generally, and in Mata, generally, a single equals sign means assignment. You'll want two equals signs when testing a condition. So,
    Code:
    if (flist == "ri") . . .

    Comment

    Working...
    X