Announcement

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

  • multiple values for same value label

    Hi everyone,

    I am working with a categorical variable called
    Code:
    plnowm
    which expresses the month in which every individual moved into his present address. The categories for the variable are the following:

    Code:
     Month moved |
      to present |
       address   |      Freq.     Percent        Cum.
    -------------+-----------------------------------
         missing |      1,822        0.76        0.76
    inapplicable |    196,551       82.24       83.00
         refusal |         27        0.01       83.01
      don't know |      1,404        0.59       83.60
         January |      2,204        0.92       84.52
        February |      2,389        1.00       85.52
           March |      2,572        1.08       86.60
           April |      2,764        1.16       87.76
             May |      2,790        1.17       88.92
            June |      3,511        1.47       90.39
            July |      3,690        1.54       91.94
          August |      4,102        1.72       93.65
       September |      5,570        2.33       95.98
         October |      3,933        1.65       97.63
        November |      2,925        1.22       98.85 
       December |      2,732        1.14      100.00
          Winter |          1        0.00      100.00
          Spring |          5        0.00      100.00
       Summer |          2        0.00      100.00
        Autumn |          2        0.00      100.00
    -------------+-----------------------------------
           Total |    238,996      100.00
    And the corresponding values for every category are the following:

    Code:
    Month moved |
     to present |
      address   |      Freq.     Percent        Cum.
    ------------+-----------------------------------
             -9 |      1,822        0.76        0.76
             -8 |    196,551       82.24       83.00
             -2 |         27        0.01       83.01
             -1 |      1,404        0.59       83.60
              1 |      2,204        0.92       84.52
              2 |      2,389        1.00       85.52
              3 |      2,572        1.08       86.60
              4 |      2,764        1.16       87.76
              5 |      2,790        1.17       88.92
              6 |      3,511        1.47       90.39
              7 |      3,690        1.54       91.94
              8 |      4,102        1.72       93.65
              9 |      5,570        2.33       95.98
             10 |      3,933        1.65       97.63
             11 |      2,925        1.22       98.85
             12 |      2,732        1.14      100.00
             13 |          1        0.00      100.00
             14 |          5        0.00      100.00
             15 |          2        0.00      100.00
             16 |          2        0.00      100.00
    ------------+-----------------------------------
          Total |    238,996      100.00
    My question is then the following: how can I make it so that more than just one value equals a certain category? e.g. I want to create a label for which the "inapplicable" label is attached not just to all observations equal to -8, but also to observations equal to 13, 14, 15 and 16 (which now are linked respectively to the categories "winter", "spring", "summer" and "autumn"). Also, I would like to do this without having to change the values of observations (e.g. putting every "14" equal to "-8") in order to mantain the integrity of the dataset.

    I appreciate any kind of help, and let me know if I was not clear enough!

  • #2
    Code:
    forval val = 13/16{
    lab def `:val lab plnowm' `val' "inapplicable", modify
    }

    Comment


    • #3
      Thank you so much for your reply Andrew!

      I have one more quesiton however; following your suggesiton, when I then
      Code:
      tab plnowm
      I get the following output:
      Code:
      Month moved |
        to present |
         address   |      Freq.     Percent        Cum.
      -------------+-----------------------------------
           missing |      1,822        0.76        0.76
      inapplicable |    196,551       82.24       83.00
           refusal |         27        0.01       83.01
        don't know |      1,404        0.59       83.60
           January |      2,204        0.92       84.52
          February |      2,389        1.00       85.52
             March |      2,572        1.08       86.60
             April |      2,764        1.16       87.76
               May |      2,790        1.17       88.92
              June |      3,511        1.47       90.39
              July |      3,690        1.54       91.94
            August |      4,102        1.72       93.65
         September |      5,570        2.33       95.98
           October |      3,933        1.65       97.63
          November |      2,925        1.22       98.85
          December |      2,732        1.14      100.00
      inapplicable |          1        0.00      100.00
      inapplicable |          5        0.00      100.00
      inapplicable |          2        0.00      100.00
      inapplicable |          2        0.00      100.00
      -------------+-----------------------------------
             Total |    238,996      100.00
      That is, Stata treats the value label "inapplicable" differently based on the value of observation (the "inapplicable" generated by value "15" is different from the "inapplicable" generated by value "16"). Is there a way to get Sata to group all the "inapplicable" values together?

      Comment


      • #4
        Is there a way to get Sata to group all the "inapplicable" values together?
        That goes counter to what you are asking in #1.

        My question is then the following: how can I make it so that more than just one value equals a certain category? e.g. I want to create a label for which the "inapplicable" label is attached not just to all observations equal to -8, but also to observations equal to 13, 14, 15 and 16 (which now are linked respectively to the categories "winter", "spring", "summer" and "autumn"). Also, I would like to do this without having to change the values of observations (e.g. putting every "14" equal to "-8") in order to mantain the integrity of the dataset.
        The only way to get the values grouped is to recode all but one of them. The one thing that you can do is to create a new variable with the levels 13-16 recoded to -8, and taking the labels of your original variable. In this way, you still have the original variable to refer to in case you want the original categorization.

        Code:
        recode plnowm (13/16 = -8), gen(plnowm2)
        label values plnowm2 `:val lab plnowm'
        tab plnowm2

        See

        Code:
        help recode
        Last edited by Andrew Musau; 29 Jul 2021, 07:14.

        Comment


        • #5
          Thanks again for your answer! You have cleared my doubts.

          Comment

          Working...
          X