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]

Re: st: Stacking data per day

From   Nick Cox <>
Subject   Re: st: Stacking data per day
Date   Mon, 17 Oct 2011 10:13:05 +0100

For this problem I would not turn to -stack-.
Your data structure is already long and lengthening it will not help.

It sounds as if you need -egen- with -by:-.

bysort day : egen pl_total = total(pl)


egen pl_total = total(pl), by(day)

are indicative examples. Look at the help for -egen-.


On Mon, Oct 17, 2011 at 10:02 AM, Julian Runge <> wrote:

> I am encountering a problem when trying to stack data in daily
> intervals. I guess this is just a basic problem, but after quite some
> effort I haven't been able to figure out how to do it. My data set
> contains profits/losses (variable pl) from a permanently ongoing
> trading game. That means, there can be several profit/loss events on
> the same day and even in the same minute (the time variable contains
> minutes, but not seconds). So, when I try to assign the data set a
> panel data structure, this is denied due to "repeated time values
> within panel". I wish to calculate the daily sums of pl. I tried to
> use the "stack" command, but wasn't able to formulate an if-expression
> telling Stata to stack the data for each day.
*   For searches and help try:

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