Announcement

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

  • New variable with mrtab

    Hello, I have created a table of multiple-choice questions and I want to generate a variable of a single value. In this case, the 11. How could I do it? (Stata 14)

    Code:
     mrtab C1a-C1c, poly response(1/30)
    
                |             Percent of     Percent
                |  Frequency   responses    of cases
    ------------+-----------------------------------
              1 |        185       15.11       41.76
              2 |         24        1.96        5.42
              3 |          6        0.49        1.35
              4 |         93        7.60       20.99
              5 |        151       12.34       34.09
              6 |          8        0.65        1.81
              7 |         18        1.47        4.06
              8 |        103        8.42       23.25
              9 |        132       10.78       29.80
             10 |         60        4.90       13.54
             11 |         88        7.19       19.86
             12 |         19        1.55        4.29
             13 |         50        4.08       11.29
             14 |         32        2.61        7.22
             15 |          8        0.65        1.81
             16 |         19        1.55        4.29
             17 |          4        0.33        0.90
             18 |         17        1.39        3.84
             19 |         24        1.96        5.42
             20 |          9        0.74        2.03
             21 |         10        0.82        2.26
             22 |         18        1.47        4.06
             23 |         11        0.90        2.48
             24 |         22        1.80        4.97
             25 |          7        0.57        1.58
             26 |         19        1.55        4.29
             27 |         16        1.31        3.61
             28 |         33        2.70        7.45
             29 |          5        0.41        1.13
             30 |         33        2.70        7.45
    ------------+-----------------------------------
          Total |       1224      100.00      276.30

  • #2
    Welcome to Statalist.

    You do not show us a sample of your input data, so we are left to learn about the user-written mrtab command and from its syntax infer that the variables C1a-C1c each contain a number between 1 and 30, and you would like to construct a 0/1 indicator variable for those observations where one of the variables contains the value 11. The following (untested) code may point you in a helpful direction.
    Code:
    egen has11 = anymatch(C1a-C1c), values(11)

    Comment


    • #3
      Thank you! It works, but the number of observations is 452 not 1224.

      452 is the total of the sample, but in the multi-reponse table the total of observations are 1224.

      Code:
      . egen has11 = anymatch(C1a-C1c), values(11)
      
      . ta has11
      
      C1a C1b C1c |
            == 11 |      Freq.     Percent        Cum.
      ------------+-----------------------------------
                0 |        364       80.53       80.53
                1 |         88       19.47      100.00
      ------------+-----------------------------------
            Total |        452      100.00

      Comment


      • #4
        Your dataset has 452 observations. Each variable in that dataset will have 452 observations. In the multi-response table, 1224 is not the number of observations, it is the total of the number of responses that lie between 1 and 30, excluding duplicates on the same observation, and you get up to 3 such responses per observation from the 3 variables C1a-C1c.

        If this doesn't address your question, you should take a few moments to review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question. It's particularly helpful touse the dataex command to provide sample data, as described in section 12 of the FAQ. Consider creating a sample of 10 observations of your data, at least one of them with 11 in one of the variables, and show us what you would expect your dataset to look like after the new variable is created.

        The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

        Comment


        • #5
          Thank you very much. It was helpful to me.

          Comment

          Working...
          X