Announcement

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

  • Creating variable and excluding data

    Hi folks,
    I'm brand new to Stata (just made the switch from SPSS) so I am running some tests I did in SPSS in Stata just to help get familiar with it.
    I want to run a logistic regression, but first I need to change a continuous variable into binary. I used this command to do it:

    recode X3TCREDCOMPSCI (0 = 0)(0.5/5 = 1), gen(CS_enrollment)

    However, in the data their is negative values as well, which I don't want to show up in the final data. So any numbers outside of the range 0-5 I want excluded from the new "CS_enrollment".
    Any recommendations on how to do this?

    Thank you!

  • #2
    Straight after you write

    Code:
    recode X3TCREDCOMPSCI (0 = 0)(0.5/5 = 1), gen(CS_enrollment)
    You can write

    Code:
    replace CS_enrollment = . if X3TCREDCOMPSCI<0
    That should do the job.

    Btw, welcome to Stata and Statalist! I've found this to be an incredibly useful forum, and even more so if you follow the guidelines in the FAQ. You can see it linked at the top of this page. Importantly, it suggests including a short data example when you post questions (so their replicable on people's machines), and that you include code within CODE delimiters (you can do this by highlighting your code and then clicking on the # symbol in the editor ribbon above where you type your text).

    Good luck and let me know if my suggestion doesn't work

    Comment


    • #3
      Awesome, thank you. I'm sure I'll figure it out when I get there, but I assume logistic regression will look for numeric values and ignore the period?
      And, thanks for the welcome and the tips on adding code. I'm sure I'll be back!

      Comment


      • #4
        Great stuff. Yes, exactly -- it will ignore missing values (the period)

        Comment

        Working...
        X