Announcement

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

  • Variable not recognized after modification

    Hi everyone,

    For company data analysis for my thesis, I wanted to create industry dummy variables based on the company's SIC Code 2's. Yesterday I successfully managed to do that by writing this code (and similar ones with different industry names):
    generate Ind_Manu=.
    replace Ind_Manu=1 if inrange(Sic_code_2,2000,3999)
    replace Ind_Manu=0 if Sic_code_2>3999
    replace Ind_Manu=0 if Sic_code_2<2000

    As a result I got a beautiful dummy variable that indicated a 1 if the company's SIC Code 2 was between 2000-3999, and a value of 0 if not.

    Today I tried patching the missing SIC Code 2 values through an alternative database. I basically copied the SIC-Code from the database and inserted it into my dataset at the place of the missing value of my Sic_code_2 variable.
    The value was still black, so I assumed it would still be recognized as a numerical value.

    However, now I wanted to update the Dummy variable with the new Sic Code 2 data, by running the following line again:
    replace Ind_Manu=1 if inrange(Sic_code_2,2000,3999)

    Yesterday this line worked perfectly fine, but somehow now I get the error: "no variables defined"
    I did not change the name of the variable, so I think it has something to do with the fact that I manually entered data into the Sic Code 2 variable.

    Does anyone know how to resolve this issue?

    Thanks in advance!

    Ruben

  • #2
    Item is resolved! The do-file had a separate MP/sheet that was not linked to my dataset. Therefore, entering a code in the worksheet that was linked to the do-file wouldn't recognize the dataset as it was not linked.

    Comment


    • #3
      Short answer is that it is hard to tell on this information. Also, in Stata there is rarely a case in which something worked yesterday and didn't work today that isn't explicable by something else being different, but I can't follow all of what you say.

      My first guess was that you created a new variable but then did not save the dataset with that new variable included. Or something similar.

      It is often hard to follow what people think they have done with copying and pasting without seeing the equivalent commands. Indeed, some members here react with horror to such practices.

      For future reference your four lines of code

      Code:
      generate Ind_Manu=.
      replace Ind_Manu=1 if inrange(Sic_code_2,2000,3999)
      replace Ind_Manu=0 if Sic_code_2>3999
      replace Ind_Manu=0 if Sic_code_2<2000
      can be boiled down to

      Code:
      generate Ind_Manu = inrange(Sic_code_2,2000,3999)
      as explained in various places e.g.

      https://www.stata.com/support/faqs/d...rue-and-false/

      https://www.stata-journal.com/articl...article=dm0099

      Showing us the result of

      Code:
      describe Ind_Manu
      
      describe Sic_code_2
      
      describe
      might help here.

      EDIT: Was being written while #2 was posted. The advice on how to generate indicator variables is still on target.

      Comment

      Working...
      X