Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Difficulties in variable calculation using panel data

From   Léon Bueckins <[email protected]>
To   [email protected]
Subject   st: Difficulties in variable calculation using panel data
Date   Sat, 30 Oct 2010 01:41:39 +0200


I hope somebody will be so kind to help me to get my approach "translated" to Stata, as I'm facing some difficulties:

I have a panel dataset and set it this way via 'xtset group_id date, daily'

Hence my data looks like this:

date | price | group_name | group_id 

01-01-2005 | 34,78 | group A | 1
01-01-2005 | 12,56 | group B | 2
01-01-2005 | 17,21 | group C | 3
01-02-2005 | 67,53 | group A | 1
01-02-2005 | 25,90 | group B | 2
01-02-2005 | 44,78 | group C | 3
…                  | …        | …           | …

a) Now I want to calculate the daily return for each group across time using:

gen return = 100 * (log(price) - log(L.price))

When doing this, I face two problems:

I. Weekends are treated as gaps, thus no return for Monday is computed, but Stata should rather use Fridays' value to compute it. May I skip the 'daily' option in the xtset command?

II. The results are wrong when I proof them randomly by hand. I guess Stata mixes up the groups. How can I tell Stata to look at the timeseries for each group separately?

b) Second, I want to compute another variable using the following formula but don't know how to tell it Stata:
dev = 1/N * sum( abs(return_i, t     -     return_m,t) ) 

N = total number of groups within panel (can be substituted by [ `=_N' ], right?)
return_i,t = return of group i at time point t
return_m,t = average return across all groups at time point t

c) finally I try to run a regression on dev

xtreg dev return …

But in the regression I want Stata to (theoretically) do one regression per t and compute the average values over all regressions, so I need just the cross-sectional and not the timeseries information in the data.

Help is greatly appreciated, so thank you very much for helping me!

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index