Announcement

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

  • Comparsion of commands

    HI can any one please let me know what is the difference between these two set of commands please


    cap gen urban = v025
    cap la var urban "type of place of residence"


    and

    gen urban = v025
    la var urban "type of place of residence"


    when I use the cap will it generate the variable or not please

    Thanks


  • #2
    See

    Code:
    help capture
    In most situations, you want the latter two commands, omitting the capture prefix.

    Comment


    • #3
      Thanks

      if I use the commands will it make any difference please

      Comment


      • #4
        Depends. If there is a problem, e.g., variable urban already exists or variable v025 does not exist or there are too many variables, then yes. With capture, you will not get an error message and the code that follows, if any, will execute. Without capture, Stata will issue an error message and stop execution (unless these lines are in a do-file and that do-file is called with option nostop).

        Comment


        • #5
          In short, if you don't know what capture does, then don't use it. There are specialized situations where it can be convenient, but it is also dangerous as you don't notice when an error occurs. So again, unless you are very very very sure about what you are doing, just don't use it.

          Or another way of saying this: if you get different results when you use capture, then my default assumption will be that the code without using capture is the correct one. If it makes no difference, than it makes no difference. If it does make a difference, trust the code without capture. So code that uses capture is typically a waste of your time. As I said above, there are exceptions, but you really need to know what you are doing. Since you asked this question, you don't, so just don't use capture.
          Last edited by Maarten Buis; 07 Nov 2023, 01:51.
          ---------------------------------
          Maarten L. Buis
          University of Konstanz
          Department of history and sociology
          box 40
          78457 Konstanz
          Germany
          http://www.maartenbuis.nl
          ---------------------------------

          Comment

          Working...
          X