|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: replacing values in a variable with rowsums, aka "ereplace"
From |
"Nick Cox" <[email protected]> |
To |
<[email protected]> |
Subject |
st: RE: replacing values in a variable with rowsums, aka "ereplace" |
Date |
Mon, 14 Jul 2008 13:05:14 +0100 |
An -ereplace- would let you use -egen- functions to -replace- variables.
There is no -ereplace- in the public domain.
I looked in my files and found that I wrote one in 1998, but I don't use
it myself and I've decided that there is little gain. Other programmers
might have similar stories.
For your problem, just use two statements rather than one:
egen rowtotal = rowtotal(d2-d40)
replace x = rowtotal if y == 2
Note the == in the second statement.
Martin Weiss has suggested that you look at -cond()-. That's a good
function to know about, but you can't use -rowtotal()- within -cond()-
as -rowtotal()- is an -egen- function. But it still might be useful for
your problem.
Nick
[email protected]
Ora John Reuter
I am searching for something that would do the equivalent of an
'ereplace'. I have a set variables for which I generated a -rowtotal-
given some condition, e.g. (egen x=rowtotal (d1-d40) if y=1), but then
I need to replace some values in that same variable (x) with a
different -rowtotal- given a different condition. I dont know how else
to explain it except to say that if there were an 'ereplace' command
the next command would look like this:
"ereplace" x=rowtotal(d2-d40) if y=2
In other words, I need to replace values in x with different sums of
variables. I need to do this for a great many conditions so typing out
the list of variables to be added for each condition would be a minor
pain.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/