如何合并类别?

时间:2019-06-18 16:09:21

标签: stata

我有一个变量fruit,具有以下类别:

1
2
3
4
5
6
7
8
9
10
20
25

我想如下折叠这些

1
2
3
4
5+

我该怎么做?

1 个答案:

答案 0 :(得分:1)

考虑您的示例:

clear
input fruit
1
2
3
4
5
6
7
8
9
10
20
25
end

tabulate fruit

      fruit |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |          1        8.33        8.33
          2 |          1        8.33       16.67
          3 |          1        8.33       25.00
          4 |          1        8.33       33.33
          5 |          1        8.33       41.67
          6 |          1        8.33       50.00
          7 |          1        8.33       58.33
          8 |          1        8.33       66.67
          9 |          1        8.33       75.00
         10 |          1        8.33       83.33
         20 |          1        8.33       91.67
         25 |          1        8.33      100.00
------------+-----------------------------------
      Total |         12      100.00

以下对我有用:

replace fruit = 5 if fruit >= 5

tabulate fruit

      fruit |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |          1        8.33        8.33
          2 |          1        8.33       16.67
          3 |          1        8.33       25.00
          4 |          1        8.33       33.33
          5 |          8       66.67      100.00
------------+-----------------------------------
      Total |         12      100.00