Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Data management

From   "Michael Blasnik" <>
To   <>
Subject   st: Re: Data management
Date   Tue, 13 Feb 2007 19:25:23 -0500

No programming needed:

egen sumvar=sum(var)
gen newvar=var/(sumvar-var)

If you have groups over which you need to calculate the sum, then you can use the -by- prefix to the egen sumvar command.

Michael Blasnik

----- Original Message ----- From: "Roy,Suryadipta" <>
To: <>
Sent: Tuesday, February 13, 2007 6:43 PM
Subject: st: Data management


I am trying to generate a new variable for the following form of data:
id var
1 A
2 B
3 C
4 D
5 E

I am trying to generate a third column where the 1st observation= A/(B+C+D+E); 2nd observation= B/(A+C+D+E), and so for all the five observations. Any help will be highly appreciated. I am wondering if I need to do some programming in such cases; so any guidance in this direction (so that I might be more self-sufficient henceforth) will be very helpful.
*   For searches and help try:

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