我需要计算一家公司过去3年(从t-2年到现在)在Stata的销售额的标准差。我的数据结构如下:公司。ID销售年度
所以每家公司都回来多次,每年都是一个新的产品线。
考虑使用SSC中的rangestat
进行模拟:
. webuse grunfeld, clear
. rangestat (count) invest (sd) invest, int(year -2 0) by(company)
. list year invest* if company == 1
+--------------------------------------+
| year invest invest~t invest_sd |
|--------------------------------------|
1. | 1935 317.6 1 . |
2. | 1936 391.8 2 52.46731 |
3. | 1937 410.6 3 49.173296 |
4. | 1938 257.7 3 83.381305 |
5. | 1939 330.8 3 76.474459 |
|--------------------------------------|
6. | 1940 461.2 3 103.08574 |
7. | 1941 512 3 93.468577 |
8. | 1942 448 3 33.790726 |
9. | 1943 499.6 3 33.941912 |
10. | 1944 547.5 3 49.761464 |
|--------------------------------------|
11. | 1945 561.2 3 32.343625 |
12. | 1946 688.1 3 77.523807 |
13. | 1947 568.9 3 71.147171 |
14. | 1948 529.2 3 82.698164 |
15. | 1949 555.1 3 20.154985 |
|--------------------------------------|
16. | 1950 642.9 3 59.592155 |
17. | 1951 755.9 3 100.66322 |
18. | 1952 891.2 3 124.31678 |
19. | 1953 1304.4 3 285.74248 |
20. | 1954 1486.7 3 305.11956 |
+--------------------------------------+