Announcement

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

  • Value label defining within a variable

    Dear Stata user, I am trying to define the value labels within a variable using the "if" code as follows. But something is wrong in my code, please suggest me

    sysuse cancer.dta
    label define z 1 "died" if drug==1 | drug==2
    label values died z

    My objective is to define value label for the variable "died", where 1 will have died if drug==1 or drug==2.
    Similarly, 0 will have alieve if drug==3

  • #2
    Value labels are static mappings from integer values to strings; they cannot be defined differently for individual observations in the data. The mapping of value 1 to the string "died" cannot depend on the values of variables in the dataset.

    I am having a very hard time understanding why would you even want this? Would being on drug 3 somehow make a dead patient (died==1) alive again?

    Edit: Crossed with #3 where Wouter is also puzzled about how the type of drug is supposed to alter the final status of a patient.

    Best
    Daniel
    Last edited by daniel klein; 23 Oct 2019, 01:57.

    Comment


    • #3
      Label define doesn't allow if conditions. You could create a new variable which satisfies your conditions and then define labels for that variable.

      I must say that I don't get the point of having labels depending on certain drugs. What about people who died with drug==3? Maybe if you give more context me or someone else will be better able to help you.

      Comment


      • #4
        Labels are just words attached to values. They are just there for cosmetics, extremely useful cosmetics, but cosmetics none the less. So if you give the value 1 the label "died", than all values 1 will receive that label. That is just what labels are.

        Instead you appear to have different forms of died, so you should create a variable that represents that.

        Code:
        . sysuse cancer.dta, clear
        (Patient Survival in Drug Trial)
        
        .
        . gen died2 = 0 if died == 0
        (31 missing values generated)
        
        . replace died2 = 1 if died == 1 & inlist(drug,1,2)
        (25 real changes made)
        
        . replace died2 = 2 if died == 1 & drug == 3
        (6 real changes made)
        
        . label define z 0 "alive" ///
        >                1 "dead"  ///
        >                2 "very dead"
        
        . label value died2 z
        
        .
        . tab drug died2, missing
        
         Drug type |
        (1=placebo |              died2
                 ) |     alive       dead  very dead |     Total
        -----------+---------------------------------+----------
                 1 |         1         19          0 |        20
                 2 |         8          6          0 |        14
                 3 |         8          0          6 |        14
        -----------+---------------------------------+----------
             Total |        17         25          6 |        48
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Dear daniel and Wouter, Please do not go into the concept of data definition. You both have focussed on understanding the data rather than what i want, I appreciate your effort. The above data set is just an example of data given by Stata. My data set is different from the above data set. I request both of you if there is a possible way to solve the problem, then please suggest rather than what data says.

          Thank you

          Comment


          • #6
            Dear Maarten, Your suggestion is good and that is the way which can solve my problem.

            Thank you

            Comment


            • #7
              Originally posted by Biswa bhusan View Post
              Dear daniel and Wouter, Please do not go into the concept of data definition. You both have focussed on understanding the data rather than what i want
              It is very hard for us to know what it is that you want. Remember, as wonderful as Stata is, the read_biswa's_mind program has not been written yet. All we know about your problem are the 72 words you have written in your question. We know nothing else about you, your project, or your data. So all we can do is take what people write seriously; If you give an example, we will assume there is a reason why you chose that example, and that that reason clarifies what you want to know. If that example makes no sense, then it becomes harder for us to understand what it is that you want to know. So examples are very good, but you have to give context. The lack of context, you telling us what that example is supposed to show, was the problem with your question.

              Originally posted by Biswa bhusan View Post
              I request both of you if there is a possible way to solve the problem, then please suggest rather than what data says.
              If you read their answers carefully, you will see they just say the exact same thing I did.



              ---------------------------------
              Maarten L. Buis
              University of Konstanz
              Department of history and sociology
              box 40
              78457 Konstanz
              Germany
              http://www.maartenbuis.nl
              ---------------------------------

              Comment

              Working...
              X