Announcement

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

  • How to fix error "outcome does not vary" for OR and logistic regression

    Dear all, I have been struggling to solve this.

    I imported data from excel file. And have a variable "screening" that is entered as "yes" and "no".

    I have tried all these commands:
    egen screeningnew = group(screening),label

    destring screening, generate (screeningnew)

    encode screening, generate (screeningnew)

    However when i want to calculate odds ratio with another variable "sex"
    command:

    tabodds screeningnew sex
    response variable screeningnew not coded 0/1

    How do i fix this? thank you so much

  • #2
    You could try something like the following.
    Code:
    assert inlist(screening, "no", "yes", "")
    generate byte screeningnew = screening == "yes" if !missing(screening)
    You might need to do something analogous with the variable for sex.

    Comment


    • #3
      It says
      226 contradictions in 226 observations

      so it cant work

      I think it is the way my variable is coded, is there a way to code the variables?
      I have went to data variables manager, to edit label, and this is the default one.
      Maybe this is not correct?

      Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	28.4 KB
ID:	1672916

      Comment


      • #4
        Anna, please read the Stata Forum's FAQ (especially Section 12) before posting: Show us the commands you are using (by toggling to the advanced editor and using code delimiters by using the button with the # symbol). Additionally, show us (parts of) your data by using the -dataex- command available at SSC.

        The outcome variable should be coded as 0 (for no/false) and 1 (for yes/true), not as 1 and 2. Use -recode- to generate a new variable Whooleypos01 to achieve this:
        Code:
        recode Whooleypos (1=0 "no") (2=1 "yes"), gen(Whooleypos01)
        (or recode the values of your variable and modify the label definitions accordingly).
        Last edited by Dirk Enzmann; 10 Jul 2022, 06:09.

        Comment

        Working...
        X