如何减去列

时间:2018-05-25 07:27:46

标签: stata

我想在下表中按apid减去值:

-----------------------------------------------
| apid  | AB | AS | BS | CS | DS | difference |  
|-------|----|----|----|----|----|----------- |
| AP013 | 43 | 36 |    |    |    | 7          |
-----------------------------------------------

例如,对于“AP013”,差异是从AS减去AB(43 - 36 = 7)。

新值还需要保存在名为diff的新列中。

你能告诉我如何在Stata中做到这一点吗?

1 个答案:

答案 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 |
   +------------------------+