【问题标题】:Growth formula with a constant base year具有恒定基年的增长公式
【发布时间】:2019-05-02 20:40:49
【问题描述】:

我有两个变量yearprice,我想计算前一个变量的增长。但是,每次计算中的基准年都是不变的。

考虑下表:

+------+-------+--------+
| year | price | growth |
+------+-------+--------+
| 2010 | 7     | -0.3   |
+------+-------+--------+
| 2011 | 9     | -0.1   |
+------+-------+--------+
| 2012 | 10    | 0      |
+------+-------+--------+
| 2013 | 12    | 0.2    |
+------+-------+--------+
| 2014 | 13    | 0.3    |
+------+-------+--------+
| 2015 | 17    | 0.7    |
+------+-------+--------+

增长公式为:

(price of second year - price of first year) / price of first year 

在我的公式中,第一年总是2012

growth = (price - price (for year=2012) ) / price (for year=2012)

如何在 Stata 中生成这个公式?

【问题讨论】:

    标签: statistics formula stata


    【解决方案1】:

    以下对我有用:

    clear
    
    input year price growth
    2010 7  -0.3   
    2011 9  -0.1   
    2012 10  0      
    2013 12  0.2    
    2014 13  0.3    
    2015 17  0.7    
    end
    
    generate wanted = (price - price[3]) / price[3]
    

    generate obs = _n 
    summarize obs if year == 2012, meanonly 
    generate wanted = (price - price[`=obs[r(min)]']) / price[`=obs[r(min)]']
    

    结果:

    list, separator(0)
    
         +--------------------------------+
         | year   price   growth   wanted |
         |--------------------------------|
      1. | 2010       7      -.3      -.3 |
      2. | 2011       9      -.1      -.1 |
      3. | 2012      10        0        0 |
      4. | 2013      12       .2       .2 |
      5. | 2014      13       .3       .3 |
      6. | 2015      17       .7       .7 |
         +--------------------------------+
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-30
      • 1970-01-01
      • 2014-02-04
      • 1970-01-01
      相关资源
      最近更新 更多