Announcement

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

  • "variable at_exp_share11 already defined" is always displayed when I run the command.

    "variable at_exp_share11 already defined" is always displayed when I run the command. But I can confirm that I have not created this variable before.

    The specific procedures are as follows



    . foreach lev in 9 1 {
    2. bys pcode_st`lev': egen at_exp_share11=total(exp_share11)
    3. gen exp_share_aggup=exp_share11/at_exp_share11
    4. }

    variable at_exp_share11 already defined

    r(110);

    Thank you in advance. I am happy to provide more information.

    Zhang Ningning


  • #2
    But I can confirm that I have not created this variable before.

    No, you can't confirm that because it isn't true. I know it isn't true both because Stata is never wrong about this particular error message in my experience, and because it is perfectly clear from your code that you have created it before.

    Specifically, you have a loop that is iterated twice, once with `lev' == 9 and then a second time with `lev' == 1. The first time through the loop, at_exp_share11 does not yet exist and your code on line 2 creates it. But the second time through the loop, at_exp_share11 is already there because you created it the first time through the loop.

    And once you fix that problem, you will run into the same problem with exp_share_aggup, which is created the first time through the loop, but hangs around and is therefore already existent the second time through the loop.

    Either you need to give these variables a different name each time through the loop, or, if you have no need of them once you are done with the loop, you can -drop- them at the bottom of the loop.

    Comment


    • #3
      It's my wrong, I found I didn't understand this command.I've solved the problem after changing the variable name.Thank you very much!

      Comment

      Working...
      X