Announcement

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

  • Print conditional statement

    I wrote this code to get Stata to print a conditional statement:

    Code:
    if p_value < alpha ///
             {
              di "Reject null"
             }
    else     {
              di "Do not reject null"
             }
    but it prints this:

    Click image for larger version

Name:	Screen shot.png
Views:	1
Size:	42.0 KB
ID:	1521951

    Is there a way to get Stata to run this "quietly" so that the only output on the screen is either "Reject null" or "Do not reject null"?

  • #2
    You can use -qui- & -noisily-:

    Code:
    qui {
    clear 
    set obs 1
    gen alpha = 1
    gen p_value = 10
    if p_value < alpha ///
             {
              noisily: di "Reject null"
             }
    else     {
             noisily: di "Do not reject null"
             }
    }

    Comment


    • #3
      Originally posted by Scott Merryman View Post
      You can use -qui- & -noisily-:

      Code:
      qui {
      clear
      set obs 1
      gen alpha = 1
      gen p_value = 10
      if p_value < alpha ///
      {
      noisily: di "Reject null"
      }
      else {
      noisily: di "Do not reject null"
      }
      }
      Thank you, Scott!

      Comment


      • #4
        Other technique that may or may not be useful:


        Code:
        . local foo 42
        
        . di cond(`foo' > 7, "it's big", "it's small")
        it's big
        
        . local foo 2.781828
        
        . di cond(`foo' > 7, "it's big", "it's small")
        it's small
        
        .

        Comment

        Working...
        X