Announcement

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

  • Rearranging data labels for clear regression

    Hello, I am new to stata and would appreciate any help, I am trying to rearrange my data so I can run a regression in a straightforward way.
    Currently my data looks like this :

    . tab GamFrq

    Frequency spends money on gambling | Freq. Percent Cum.
    ----------------------------------------+-----------------------------------
    2 or more times a week | 846 13.95 13.95
    Once a week | 1,786 29.45 43.40
    Less than once a week, more than once a | 589 9.71 53.12
    Once a month | 665 10.97 64.08
    Every 2-3 months | 742 12.24 76.32
    Once or twice a year | 1,436 23.68 100.00
    ----------------------------------------+-----------------------------------
    Total 6,064 100.00

    But ideally I want it the other way around starting with the least frequent and so on.

    the data type is byte in case this information is important

    Many thanks to anyone who can help


  • #2
    See

    Code:
    help recode
    Assuming that the underlying values range from 1-6, the command should be

    Code:
    recode GamFrq (1 = 6) (2 = 5) (3 = 4) (4 = 3) (5 = 2) (6 = 1), gen(GamFrq_R)
    tab GamFrq_R

    To see the underlying values:

    Code:
    lab list `:val lab GamFrq'
    Last edited by Andrew Musau; 15 Mar 2023, 10:34.

    Comment


    • #3
      Alternatively:
      Code:
      gen GamFrq_R = 7 - GamFrq

      Comment


      • #4
        That worked thank you very much

        Comment


        • #5
          You probably want to reverse the labels, too. Here is one way, using elabel (SSC):

          Code:
          elabel adjust : recode GamFrq (1/6 = 6/1)
          The code above will replace the original variable. People will tell you that you should never do that. I do not think it is a problem if you preserve all information, which is the case here.

          Comment

          Working...
          X