Announcement

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

  • Editing a variable

    Hello,
    I am a new stata user so please excuse me if my question is obvious.
    If I set up a new calculated variable. I would like to know how I can view and edit the formula that I used to set up the variable. eg if I reviewed it at a later date I may have forgotten how it was set up or if it is a complicated formula I would like to review how I set it up.
    Is there a way to retrieve or edit the formula?
    Thank you
    Simon

  • #2
    It's good and recommended practice to keep a log of your commands which includes the definitions of the variables you've created in terms of the syntax you used to create them. Typically that means using generate. Other commands that create variables are even if they seem different just using generate out of sight.

    Definitions aren't otherwise stored with variables in any sense unless exceptionally you put the definition in a variable label and it suffices. For example, rnormal() wouldn't be enough to re-create the same values exactly. Even if a definition were stored in a variable label you would have to extract it yourself. There is no sense in which Stata is aware that the definition is stored any where except through the values of a variable.

    If you decide that a variable needs to be something else you need to use the replace command.

    Suppose you went

    Code:
    gen y = log(x) 
    and then realised that you wanted log10(x) instead. You could then go

    Code:
    replace y = log10(x)
    but note that if x had been changed in the interim that is not necessarily equivalent.

    I sense that you're looking for something equivalent to a spreadsheet functionality, but it doesn't exist in Stata. Because everything you do (small exceptions) can be defined in terms of a command language, you're encouraged and expected to keep track of what you did, and indeed you should care.

    Comment


    • #3
      Thank you
      That was very helpful

      Comment


      • #4
        Just a note after Nick’s advice, you may also choose one of these options: include the information about the formula in a do-file; use - notes - command to add, well, notes with the information you wish to store. Please type - help notes - and check whether this resource is helpful to you.
        Best regards,

        Marcos

        Comment


        • #5
          Even more basic, most of us use an editor for our programs. Stata's do-file editor works well. Then you save your program. This means you have an explicit record of all your calculations and can load more data without a lot of trouble. It also means when you debug something it stays debugged. Trying to do much with interactive is just asking for trouble.

          I only use interactive when I want a long statement for a use command or to try things out.

          Comment

          Working...
          X