Announcement

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

  • Question about binary outcome and logit (multinomial) in Stata

    As a novice of Stata, I am facing some coding issues. I have loaded my Excel file (3 vars, 30 obs), and when I put in the following commands: **generate Y = .
    replace Y = 0 if binary_outcome = "0"
    replace Y = 0 if binary_outcome = "no"
    logit Y binary_numeric i.X**
    I get the following result "binary_outcome not found", and "variable binary_numeric not found".
    What am I doing wrong?


  • #2
    Stata is telling you, first, that there is no variable called binary_outcome in your Stata data set after you import the data from Excel. You didn't show any example data from the import, so it is hard to be specific about why this happened. But in general there are a few possibilities:

    1. There is no column in the Excel file that is headed by "binary_outcome", so no such variable would be created in Stata.
    2. There is such a column, but when you imported the data from Excel, you didn't tell Stata to recognize the row in which that header appears as a variable name ratherthan as data.

    Moving on, you get "variable binary_numeric not found" because your subsequent commands will not work in the absence of the variable binary_outcome.

    I should also point out that the sequence of generate/replace commands you show would not, in any case, produce a satisfactory variable Y for use in logistic regression (or any other estimation command). The reason is that none of the commands ever produce a non-missing value other than 0. When you run -logit- or any other estimation command, observations containing missing values for any of the model variables are omitted. So what is left is an estimation sample in which the value of Y is always 0. But you cannot do a logistic regression when the outcome variable never varies.

    In the future, when asking for help with code you should always show example data, so that those who want to help you can work with your code and data to see what is going on and provide specific fixes to your problems. The way to show example Stata data is with the -dataex- command. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment

    Working...
    X