[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: Re: systematically creating new observations
It actually isn't that easy/trivial. If you have a group variable (not
shown in your example, but you mention there are many groups) and a subgroup
var (e.g., gender in your example), then you could:
egen groupsum=sum(points), by(groupvar)
bysort groupvar (subgroupvar): gen byte last=_n==_N
expand 2 if last
bysort groupvar (subgroupvar): replace points=groupsum if _n==_N
bysort groupvar (subgroupvar): replace subgroupvar="All" if _n==_N
drop groupsum last
This approach calculates the sums you seem to want for each group, flags the
last observation in each group and adds an observation to the end and then
plugs in that sum and the title "All" into that new observation. If you
have other variables, they will be copied to the All group from the prior
observation (the one that was expanded).
----- Original Message -----
From: "daphna" <firstname.lastname@example.org>
Sent: Friday, June 18, 2004 1:59 PM
Subject: st: systematically creating new observations
> I am wondering if anyone can recommend a way to systematically create
> Suppose I have a set of observations that looks something like this:
> What I want to do is create a new observation (not a new variable), called
> ALL so that the data would look something like this:
> Of course, I need to do this more than once. I have to do it for
> of groups.
> Is there a systematic way to add such an observation?
> It seems pretty obvious but I cannot seem to figure it out.
> Thanks so much for your help.
> Daphna Bassok
> Research Assistant
> Center For Research On Education Outcomes
> Stanford University
> Stanford, CA 94305
> Phone: (650) 725-6169
* For searches and help try: