Stata 生成变量
我有一个数据集,其中的变量类似于图像 我想为血清群和所有抗生素[青霉素四环素]制作一张表。抗生素有价值标签Stata 生成变量,stata,Stata,我有一个数据集,其中的变量类似于图像 我想为血清群和所有抗生素[青霉素四环素]制作一张表。抗生素有价值标签(“敏感”“耐药”) 这里我只考虑“抵抗”值。 我尝试了以下代码: gen All_antibiotic =1 if penicillin=="Resistant" replace All_antibiotic =2 if ampicillin=="Resistant" . . tab All_antibiotic serogroup 但它并没有给出完整的表格 这里有各种困难: 您没有提
(“敏感”“耐药”)
<>这里我只考虑“抵抗”值。
我尝试了以下代码:
gen All_antibiotic =1 if penicillin=="Resistant"
replace All_antibiotic =2 if ampicillin=="Resistant"
.
.
tab All_antibiotic serogroup
但它并没有给出完整的表格 这里有各种困难:
重塑
之前,您需要重命名
clear
input id group str4(y1 y2 y3)
1 1 frog frog toad
2 1 frog toad toad
3 1 toad toad toad
4 2 frog frog frog
5 2 frog frog toad
6 2 frog toad toad
end
preserve
reshape long y, i(id) j(which)
describe
tab group y
| y
group | frog toad | Total
-----------+----------------------+----------
1 | 3 6 | 9
2 | 6 3 | 9
-----------+----------------------+----------
Total | 9 9 | 18
restore
为什么要反向编辑?您删除了对英语和代码表示的改进。按照答案所暗示的思路改进这个问题会更好。解释有关编辑的信息。