Announcement

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

  • brand new to stata - trying to recode

    Hi all,
    I am absolutely brand new to STATA, and have been given a fairly large undertaking.
    Any help at all would be infinitely appreciated!

    I have a variable 'type of cancer' which is broken down into 13 different diagnoses and 1 'no cancer'

    I would like to recode this variable in 2 different ways:
    1. so that it is just 2 levels - any cancer vs no cancer
    2. and also, I would like to join 2 of the variables together (throat cancer + pharyngeal cancer) and then collapse the rest into 'any cancer' and keep the 'no cancer' as it is (so I can compare).

    I have been told to 'recode no cancer as missing" but I'm not sure what that means.

    I am not sure what the command would be to generate these new variables, while also not changing the original variable.

    I'm not sure if this is the appropriate place to ask, but I'm in need of assistance and I would truly appreciate any insight!!

    Thank you
    Al


    Last edited by Alan Jeddi; 13 Jun 2018, 09:19.

  • #2
    Hi Alan, welcome to Statalist.

    Please look for learning modules, I suggest here. Also, consider sharing a snippet of your data to ease the elaboration of solutions.

    I suggest not recoding the original variable, in case you want to refer to the original one, you can. The answer you want depends on several factors that can't be ascertained without looking at a snippet of your database - are there missing values, is the variable a string, if it is coded, how is it coded?

    In general terms, what I would do is:

    Code:
    clonevar cancer = typeofcancer //cancer is a new var that's equal to your original typeofcancer var
    replace cancer = "0" if cancer == "no cancer" //assuming your original variable is in string format, this converts all "no cancer" to "0".
    replace cancer = "1" if cancer != "no cancer" //assuming your original variable is in string format, this converts all non "no cancer" to "1".
    destring cancer, replace //this transform your string variable into numeric

    Comment


    • #3
      I'm sympathetic to you as a new user of Stata - it's a lot to absorb. And even worse if perhaps you are under pressure to produce some output quickly. Nevertheless, I'd like to encourage you to take a step back from your immediate tasks.

      When I began using Stata in a serious way, I started, as have others here, by reading my way through the Getting Started with Stata manual relevant to my setup. Chapter 18 then gives suggested further reading, much of which is in the Stata User's Guide, and I worked my way through much of that reading as well. There are a lot of examples to copy and paste into Stata's do-file editor to run yourself, and better yet, to experiment with changing the options to see how the results change.

      All of these manuals are included as PDFs in the Stata installation (since version 11) and are accessible from within Stata - for example, through the PDF Documentation section of Stata's Help menu. The objective in doing the reading was not so much to master Stata as to be sure I'd become familiar with a wide variety of important basic techniques, so that when the time came that I needed them, I might recall their existence, if not the full syntax, and know how to find out more about them in the help files and PDF manuals.

      Stata supplies exceptionally good documentation that amply repays the time spent studying it - there's just a lot of it. The path I followed surfaces the things you need to know to get started in a hurry and to work effectively.

      Comment

      Working...
      X