Announcement

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

  • "var2 = var1+ 2". How to automatically change the values of var2 when I change var1?

    Hi!

    I'm working on Stata 12 from a Mac.

    I have a variable of the form: var2 = var1 + 2.
    Initially, imagine I have var1 = 2.

    I want to replace var1 such that: var1 = 3.
    My problem as of now:
    I do -replace var1 = 2-, and var1 obviously becomes 2, but var2 is still equal to 2 + 2 = 4. It doesn't take into account that I changed the value of var1.
    How can I tell Stata to adjust the value of var2 accordingly? That is, how can I tell Stata that var2 is now equal to 3+2 = 5?

    Would anyone have tips on how to do this?
    Note: I'm giving a simple example, but my actual variables are more complicated than that, and I change the variables before running estimations various times. It would be pretty inconvenient to have to drop and re-create the variables.

    Thanks in advance!

    Ana

  • #2
    If it's part of the definition of var2 that it's always var1 + 2, then any change to var1 must be matched by a change to var2. Stata's not a spreadsheet and has no way to make changes automatically.

    Comment


    • #3
      Hi Nick,

      Thanks for your answer!

      Actually, to be precise, I have:
      var2 = var1 + 2 if var3 >= 10
      var2 = var1 + 2 + epsilon if var3 < 10
      Sorry for the confusion!

      Does it not work in this case?

      Comment


      • #4
        Stata does things in sequence, and you have complete control over this sequence. If you want a change in one variable to affect other variables, you must be explicit and make sure that things are done in the sequence you want. In your do-file write:
        Code:
        replace var1=3
        replace var2=var1+2
        So it is not like Excel where a change in one cell may automatically induce changes in other cells. This can be very useful, but also dangerous because the rules laid down in an Excel spreadsheet can be quite intransparent.

        Comment


        • #5
          Same principle. Whatever relationships are inbuilt are your responsibility to maintain, regardless of what epsilon is.

          Comment


          • #6
            Oh, I see. Thanks a lot, Nick!

            Comment

            Working...
            X