Announcement

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

  • qui and quietly are the same command? but "quietly" brings syntax error

    Hello everyone,

    I am leaning stata by following already made "do foles"
    The command below works fine. But as I replace qui with "quietly" (as I believe these two are the same command), it brings an error msg : "invalid syntax"
    Could you please explain me what is wrong?

    PS. would you recommend other good sources to learn stata - I want to learn by replicating already made do files - or if there is any other good ways to learn.
    Thanks a lot!

    qui {
    rename State state_old
    gen state =.
    replace state = 00 if state_old==99
    label define state_lbl 00 "notdefined" 01 "somewhere" 01 "delhi" ///
    label value state state_lbl
    }

  • #2
    Hello Su,

    The Stata Manuals are always a great starting point.

    Below, an example, demonstrating that qui and quiet give the same results:



    Code:
     
    . sysuse auto.dta
    (1978 Automobile Data)
    
    . qui regress mpg foreign
    
    . estimates store model1
    
    . quietly regress mpg foreign
    
    . estimates store model2
    
    . estimates table model1 model2
    
    ----------------------------------------
        Variable |   model1       model2    
    -------------+--------------------------
         foreign |  4.9458042    4.9458042  
           _cons |  19.826923    19.826923  
    ----------------------------------------
    Last edited by Marcos Almeida; 01 Sep 2016, 04:49.
    Best regards,

    Marcos

    Comment


    • #3
      Su:
      welcome to the list.
      The error message may be caused by an inconsistency in your code, which has nothing to do with -quietly- or -quite- :
      Code:
      label define state_lbl 00 "notdefined" 01 "somewhere" 01 "delhi" ///
      label value state state_lbl
      should be:
      Code:
      label define state 00 "notdefined" 01 "somewhere" 01 "delhi" ///
      label value state state
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        I don't think the quietly (qui) is the problem here at all.

        Code:
         
        label define state_lbl 00 "notdefined" 01 "somewhere" 01 "delhi" ///
        label value state state_lbl
        is doubly problematic. You are trying to define a label for 1 with two different labels. And the label value command must be on a new line: the continuation comment makes it illegal.

        Note that the leading zeros (i.e. 00 rather than 0 and 01 rather than 1) will just be ignored. Demonstration:

        Code:
        . label def something 00 "zero" 01 "one"
        
        . label li something
        something:
                   0 zero
                   1 one

        Comment


        • #5
          Carlo:

          We posted at the same time.

          There would be nothing wrong with

          Code:
          label define state_lbl 00 "notdefined" 01 "delhi"  
          label value state state_lbl
          See #4 for my diagnosis.

          Comment


          • #6
            Nick:
            thanks for the helpful insight.
            My bad: I usually double click on the same variable for label creation and never considered different approaches.
            However, it sounds weird that the original poster reports a problem with -quietly- only: perhaps she may be willing to clarify in a next message.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Carlo: What was reported doesn't surprise me. quietly suppresses output but not error messages. So, you don't necessarily get to see which command inside the block is wrong.

              Try this:

              Code:
              quietly { 
                 sysuse auto, clear
                 regress mpg weight 
                 display "Carlo is a nice guy" 
                 regress make mpg 
              }
              The error comes from the last command, but it takes extra knowledge to know which command is the problem.

              Comment


              • #8
                Nick:
                thanks for the clarification via a flattering toy-code!
                Kind regards,
                Carlo
                (Stata 19.0)

                Comment


                • #9
                  I have been having the same issue with the command quietly quietly {
                  forvalues i=1(1) `mc' {
                  preserve
                  clear
                  set obs 500
                  gen x1=rnormal()*1+1
                  gen x2=rnormal()*2+2
                  gen u=rnormal()
                  gen y=1+2*x1+5*x2+u
                  reg y x1 x2
                  local x1coef=_b[x1]
                  local x2coef=_b[x2]
                  local const=_b[_cons]
                  restore
                  replace data_store_x1=`x1coef' in `i'
                  replace data_store_x2=`x2coef' in `i'
                  replace data_store_cons=`const' in `i'
                  }
                  }

                  this is my code and I have been getting the quietly { syntax error

                  Comment


                  • #10
                    the quietly { syntax error
                    Doesn't mean much to me, what's the error code you're getting? Does the code work when you take away quietly?

                    Comment


                    • #11
                      Where is local macro mc defined?

                      Comment

                      Working...
                      X