我想在下表中按apid
减去值:
-----------------------------------------------
| apid | AB | AS | BS | CS | DS | difference |
|-------|----|----|----|----|----|----------- |
| AP013 | 43 | 36 | | | | 7 |
-----------------------------------------------
例如,对于“AP013”,差异是从AS
减去AB
(43 - 36 = 7)。
新值还需要保存在名为diff
的新列中。
你能告诉我如何在Stata中做到这一点吗?
答案 0 :(得分:1)
您只需生成一个新变量diff
:
clear
input str5 apid AB AS
"AP013" 43 36
end
generate diff = AB - AS
list
+------------------------+
| apid AB AS diff |
|------------------------|
1. | AP013 43 36 7 |
+------------------------+