计算Stata多年来的标准偏差

发布于 2025-02-11 11:01:56 字数 98 浏览 0 评论 0原文

我需要在Stata中计算过去3年(从T-2年起)在过去3年中的销售标准偏差。我的数据具有以下结构: 公司ID销售年份,

因此每个公司都会多次回来,每年都是一条新产品线。

I need to calculate the standard deviation of a company's sales over the last 3 years (from year t-2 until now) in Stata. My data has the following structure:
Firm.ID SALES YEAR

So each company comes back multiple times, with each year being a new line.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光匆匆的小流年 2025-02-18 11:01:56

使用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 |
     +--------------------------------------+

Consider this analogue using rangestat from SSC:

. 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 |
     +--------------------------------------+
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文