Calcule el crecimiento interanual del PIB para cada trimestre

I want to compute in Stata year on year growth rate of the GDP for each quarter. Basically, I want to compute : (gdp_q1y1980-gdp_q1y1979)/gdp_q1y1979.

preguntado el 05 de febrero de 14 a las 17:02

It's a pure stata question so there's no need for R. Right ? -

2 Respuestas

// create some silly example data
clear
set obs 10
gen time = _n
format time %tq
gen gdp = _n^2*100

// do the computation
tsset time
gen growth = S4.gdp / L4.gdp

// admire the result
list

Para más información, visite aquí.

Respondido 05 Feb 14, 18:02

I prefer @Maarten Buis' solution but know also that you could use subíndice:

sort time
gen growth = (gdp / gdp[_n-4]) - 1

Ejecutar help subscripting for details (or http://www.stata.com/help.cgi?subscripting).

Note that extra care must be taken if, for example, there is a gap in your time series:

. clear all

. set more off

. 
. // create some silly example data
. set obs 15
obs was 0, now 15

. gen time = _n

. format time %tq

. gen gdp = _n^2*100

. 
. // create a gap deleting 1962q4
. drop in 11
(1 observation deleted)

. 
. // using -tsset-
. tsset time
        time variable:  time, 1960q2 to 1963q4, but with a gap
                delta:  1 quarter

. gen growth = S4.gdp / L4.gdp
(5 missing values generated)

. 
. // subscripting
. sort time

. gen growth2 = (gdp / gdp[_n-4]) - 1
(4 missing values generated)

. 
. list, separator(0)

     +--------------------------------------+
     |   time     gdp     growth    growth2 |
     |--------------------------------------|
  1. | 1960q2     100          .          . |
  2. | 1960q3     400          .          . |
  3. | 1960q4     900          .          . |
  4. | 1961q1    1600          .          . |
  5. | 1961q2    2500         24         24 |
  6. | 1961q3    3600          8          8 |
  7. | 1961q4    4900   4.444445   4.444445 |
  8. | 1962q1    6400          3          3 |
  9. | 1962q2    8100       2.24       2.24 |
 10. | 1962q3   10000   1.777778   1.777778 |
 11. | 1963q1   14400       1.25   1.938776 |
 12. | 1963q2   16900    1.08642   1.640625 |
 13. | 1963q3   19600        .96   1.419753 |
 14. | 1963q4   22500          .       1.25 |
     +--------------------------------------+

The results for the solution with subscripts (variable growth2) are messed up once the gap begins (1963q1). A good reason, I think, to prefer tsset.

Respondido 05 Feb 14, 21:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.