Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: calculating percentage changes in an unbalanced panel data set

 From Rebecca Pope To statalist@hsphsun2.harvard.edu Subject Re: st: calculating percentage changes in an unbalanced panel data set Date Tue, 5 Mar 2013 20:02:29 -0600

```You have inflation measured on a daily basis? My guess is not. In all
likelihood, what you have is monthly data that happens to be coded
01mmmYYYY. Stata, however, does not know this.

gen month = mofd(time)   // get date in month format
format month %tm
tsset id month

Now Stata knows you have monthly changes, so it doesn't appear that
you have many missing observations within your panel simply due to
false "gaps" because of how your data is recorded.

Once you have -tsset- your data, you can use the lag operator.
Otherwise, based on what you are doing, there isn't much point in
-tsset-. Using lags to calculate a change in the inflation rate would
be as so:

gen p2 = (inf/L.inf-1)*100   // L. is Stata's lag operator (see -help
tsvarlist- if unfamiliar)

If you are wanting inflation since "baseline" rather than
period-to-period inflation:
bys id (mon): gen p2_alt = (inf[_n]/inf[1]-1)*100   // note here that
the time variable is in ()

In your original code, you had "bys country time". The problem with
this is that Stata is looking within country _and_ time and counting
observations. Because you only have one observation at each time
period, you get missing values. Placing time in parentheses tells
Stata to sort by that value but not to count within it.

p2 will result in missing values if your panel data are still
unbalanced after correcting for monthly observations. p2_alt will give
you a value at every point in your series. However, the two provide
fundamentally different information. Your example of 2/1 leaves the
ultimate question unclear so I've given you code for both.

Regards,
Rebecca

On Tue, Mar 5, 2013 at 5:27 PM, Tzaloupas Dimitrov
<tzaloupas1232@yahoo.gr> wrote:
>
>
>
>
> Dear all,
>
> I have some time series observations (inflation) for a set of countries
>
> The panel data set is unbalanced, that is,
>
> egen id = group(country), label
> tsset id time
>        panel variable:  id (unbalanced)
>         time variable:  time, 01oct2008 to 01nov2011, but with gaps
>                 delta:  1 day
>
> within each country I want to find the percentage change of inflation.
>
> I tried
>
> bysort country time : gen p2=(inf[2]-inf[1]/inf[1])*100
>
> but I get this message
> (500 missing values generated)
>
>  Am I doing something wrong?
>
>
>
> I use Stata 11
>
> Any help/code is greatly appreciated
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/
```