Announcement

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

  • How to generate a new variable using an existing variable

    Hello everyone, I am learning Stata and need some help. I have a variable called mrs_90day which has participant scores ranging from 0-6. I want to create a new variable called mrs_90daysurvivors using the same data in the mrs_90day variable, except this time I would like to exclude those with a score of 6 and only remain with those with a score of 0-5. How do I go about with this. Thank you.

  • #2
    Code:
    gen mrs_90daysurvivors = mrs_90day if mrs_90day < 6
    Note, because you do not show example data, I am writing this code for an imaginary data set that might resemble what you have. If I have imagined it wrong, then this code will not work, and we will both have wasted our time. If that happens, post back with example data using 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.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Thank you Clyde. The code has worked well. Let me figure out how to do the dataex option for future questions.

      Comment

      Working...
      X