Announcement

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

  • Error code r(110) variable XXX already defined

    Someone please help, am trying to create logs for my variables and I keep getting error ______ already defined. See below the error. Any idea on how I can resolve this?

    . gen ln_ value_added=ln( value_added)
    value_added already defined
    r(110);

  • #2
    See the Advice in the FAQ for details on how to present code. I guess you have a space in the middle of your intended variable name, so that you have

    Code:
    gen ln_ value_added = ln(value_added)
    You need

    Code:
    gen ln_value_added = ln(value_added)

    Comment


    • #3
      Many thanks for this

      Comment


      • #4
        Hi everyone, I need some help. How can I resolve this problem " variable __00000R already defined"? I am doing an LM estimation with tempvar. Thank you

        Comment


        • #5
          Without any code we are reduced to guesswork.

          Consider

          Code:
          tempvar foo
          gen `foo' = 42
          gen `foo' = 24
          The second generate will fail because the variable already exists. But the message you see will not mention the temporary name you chose. It will mention the temporary variable name that Stata is using. Left to its own devices Stata's habit is that all temporary variable names are 8 characters long, belong with double underscores and start at __000000.

          So check your code for such a problem. Or even better, use set trace on to see where the problem occurs.

          Comment


          • #6
            Thank you very much! I mistakenly generated the same variable twice. Many thanks

            Comment


            • #7
              I am experiencing a similar problem. The code is as follows:
              . reshape wide aar kjonn hf alder1 alder2 komNrHjem2 grunnopphold Hendelser_grunnopphold tidsavstand_hendelser dager_siden_grunnopph
              > old institusjonID_SHO behandlingssted2 PsykinstID DPS institusjonID_TSB institusjonID_BUP institusjonID_ASSOM institusjonID_ASPH i
              > nstitusjonID_REHAB fraSted ANKFRA_2012_2013 fraInstitusjonID fraInstitusjonID_2012_2013 inntilstand innmateHast utTilstand tilSted
              > uttil_2012_2013 tilInstitusjonID utinst_2012_2013 liggetid omsorgsniva3 sektor hdiag bdiag1 bdiag2 bdiag3 bdiag4 bdiag5 bdiag6 bd
              > iag7 bdiag8 bdiag9 bdiag10 bdiag11 bdiag12 bdiag13 bdiag14 bdiag15 bdiag16 bdiag17 bdiag18 bdiag19 henvFormal henvType typeFormali
              > tet_1 typeFormalitet_2 typeFormalitet_3 typeFormalitet_4 typeFormalitet_5 typeFormalitet_6 typeFormalitet_7 dager_død bd1 ncode1 b
              > d2 ncode2 bd3 ncode3 bd4 ncode4 bd5 ncode5 bd6 ncode6 bd7 ncode7 bd8 ncode8 bd9 ncode9 bd10 ncode10 bd11 ncode11 bd12 ncode12 bd13
              > ncode13 bd14 ncode14 bd15 ncode15 bd16 ncode16 bd17 ncode17 bd18 ncode18 bd19 ncode19 nmis Nbd sep hd1 ncodeh F_bidiag Fkap addDi
              > ag ,i(lopenr) j(counter)
              (note: j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 4
              > 4 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
              > 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 1
              > 23 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
              > 156 157 158 159 160 161 162 163 164 165)
              variable bdiag11 already defined
              r(110);

              I tried drop bdiag* , then I get this error:
              variable bd11 already defined
              r(110);

              Is there some issue with having too many variables with the same base? Or is there another problem?

              Thank you!

              Comment


              • #8
                Please put the output in [CODE] tags so we can understand it

                Comment


                • #9
                  The reshape command looks for stubs in variable names, not full names. Therefore, the inclusion of bdiag1 will lead Stata to reshape wide all variables starting with bdiag1. When it arrives at bdiag11, it notices it already took care of that variable when going over bdiag1.
                  You can simplify your command by replacing just bdiag (or even just bd to include all these vars in one go). Same applies for all vars starting with ncode

                  edit:
                  I do have to say that this reshape command makes little sense on the face of it. It would seem as if you would be trying to end up with one row of data, which is not a useful data structure. You might want to explain what you're after in analytical purpose and post a sample of your data using dataex (and code blocks, please). If you do so, please create a new thread for that question.
                  Last edited by Jorrit Gosens; 11 Jan 2016, 08:13.

                  Comment


                  • #10
                    I am having the same problem as Eva. I list only the stubs. For example, I have a measure whose variable names are ils1-ils12. When I only list "ils" I get an error saying "ils" is an ambiguous abbreviation. I have looked through the support materials and haven't been able to figure out what I am doing wrong. I have tried adding "*" after ils (ils*), but then once the process reaches ils11 it says that it is already defined.

                    Comment


                    • #11
                      Welcome to Statalist.

                      Without seeing the command that you are running we cannot tell you what is wrong with that command. Please scroll to the top of this page, click on FAQ, and review sections 9-12 on how to present your problem in a way that helps us help you.

                      Comment


                      • #12
                        Hi William,

                        Thank you for the welcome, and I appreciate your patience with me as I become socialized to the norms of the forum.

                        I am running STATA/SE 14.2 for Mac (64-bit).

                        The data are a simple pre/post (two waves). The same respondents were given a battery of measures prior to a training, and then after the training. I would like to transform the long dataset to a wide data set for analysis.

                        Here is the syntax I used:

                        Code:
                        reshape wide ils ics oric taas imp_strat ebp hear, i(id) j(wave)
                        The variables listed in the syntax are stubnames. For example, ils is a measure with 12 items. The actual variable names are ils1, ils2 . . . ils12. Though the number of items vary, the remaining variables are formatted the same [stubname1, stubname2, etc.]. Each respondent has a unique identifier (id), and a wave assignment.

                        When I run the code I receive the following error message.

                        ils ambiguous abbreviation r(111);
                        Thanks for your help!


                        Comment


                        • #13
                          I see the problem.

                          First, let me quote a piece from help reshape

                          ... and where stubnames are variable names (long->wide), or stubs of variable names (wide->long) ...
                          So for your reshape wide, you definitely want a list of variable names like the following:
                          Code:
                          reshape wide ils* ics* ... hear*, i(id) j(wave)
                          But that leads to another problem. When ils1 is reshaped wide, the two new variables will be ils11 and ils12 - ils1 with the value of wave appended. But there already is a variable named ils11 in the dataset, and Stata does not realize at this point that it will become ils111 and ils112 after the reshape. So we need to rename your variables slightly to avoid this problem - and as a side effect, their names will be a little more readable after the reshape. Here's a sample; the technique is described in the output of help rename group .
                          Code:
                          . list
                          
                               +--------------------------+
                               | id   wave   ils1   ils11 |
                               |--------------------------|
                            1. |  1      1    101    1101 |
                            2. |  1      2    102    1102 |
                               +--------------------------+
                          
                          . reshape wide ils*, i(id) j(wave)
                          (note: j = 1 2)
                          variable ils11 already defined
                          r(110);
                          
                          . rename (ils*) (=_)
                          
                          . list
                          
                               +----------------------------+
                               | id   wave   ils1_   ils11_ |
                               |----------------------------|
                            1. |  1      1     101     1101 |
                            2. |  1      2     102     1102 |
                               +----------------------------+
                          
                          . reshape wide ils*, i(id) j(wave)
                          (note: j = 1 2)
                          
                          Data                               long   ->   wide
                          -----------------------------------------------------------------------------
                          Number of obs.                        2   ->       1
                          Number of variables                   4   ->       5
                          j variable (2 values)              wave   ->   (dropped)
                          xij variables:
                                                            ils1_   ->   ils1_1 ils1_2
                                                           ils11_   ->   ils11_1 ils11_2
                          -----------------------------------------------------------------------------
                          
                          . list
                          
                               +------------------------------------------+
                               | id   ils1_1   ils11_1   ils1_2   ils11_2 |
                               |------------------------------------------|
                            1. |  1      101      1101      102      1102 |
                               +------------------------------------------+
                          
                          .
                          OK, having gone through all that, let me offer up some more advice. I don't know what you want to accomplish in your analysis or how you plan to do so, but still, the experienced users here generally agree that, with few exceptions, Stata makes it much more straightforward to accomplish complex analyses using a long layout of your data rather than a wide layout of the same data. So if you discover that it seems inconvenient to accomplish what you need with the wide layout - if you find yourself wanting to loop over the wave1/wave2 pairs of variables - consider going back to the data as you now have it and starting from there.

                          Comment


                          • #14
                            Thank you very much William, this is incredibly helpful!! You are a wizard

                            I went back to the help reshape document. Do you mind expanding on why the stubnames required the " * "? I.e. what is the rule of thumb that I would follow to know that an " * " is required in future cases?

                            Thanks again, really amazing!

                            Comment


                            • #15
                              The rule is exactly the phrase I quoted in post #13.

                              If you are doing a reshape wide, the stubnames must be variable names. Stata will use each variable name as a stub, appending (in your case) the values of wave to the ends of them to create new variables. In your case, "ils" is not a variable name.

                              What Stata is telling you is that your command should be
                              Code:
                              reshape wide ils1 ils2 ils3 ... ils12 ics1 ... , i(id) j(wave)
                              But that's a lot of typing of lists of similar variable names, and Stata lets you abbreviate variable lists using an asterisk, so
                              Code:
                              ils*
                              is expanded by Stata into a list of every variable name starting with "lis".

                              If you are doing a reshape long, the stub names must be the stub - the portion of the existing variable name that isn't going to be used to provide the value of the "j" variable. So if you were going to take your wide data and reshape it back to long, the stubs would be ils1_ ils2_ ils3_ ... ils12_. Stata would use the part after ils1_ and ils2_ and ils3_ ... ils12_ to create the value of wave, and the stubs would be the names of the new variables being created.
                              Last edited by William Lisowski; 29 Jun 2017, 06:03.

                              Comment

                              Working...
                              X