Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: How to make a code faster - alternatives to egen var = concat(vars) ?,
From
"Nick Cox" <[email protected]>
To
<[email protected]>
Subject
RE: st: How to make a code faster - alternatives to egen var = concat(vars) ?,
Date
Thu, 17 Jun 2010 22:02:51 +0100
I'll -collapse- and -merge- back again.
Nick
[email protected]
Tiago V. Pereira
Thank you so much again, Antoine!
Yes, this is a very efficient way! However, I could not figure out how I
can save the combination of the categorical variables that a specific
meanX refers to.
For example, the commands
sysuse auto, clear
bysort foreign rep78 : mymean price
scalar dir
show a list of scalars containing the mean of the ith combination, but I
don't know if the mean10 refers to the combination "foreign = Foreign,
rep78 =4" or "foreign = Foreign, rep78 = 5"
[Actually I do in this specific case if I take a look at each value from
the output.]
Nevertheless, assuming a very large number of categorical variables
(n>10), I cannot write a loop and say that mean2451 refers to the
combination x1==0 x2==0 x3==2 x4==0 x5==2 and x6==1. I want to summarize
the mean of this combination in group 1 and generate a separate variable
for group 2.
for example
bysort x1 x2 x3 x4 x5 x6 : mymean score if group==1
*/ yes, -mymean- needs further amendments to have this option
replace score = mean2451 if
group==2&x1==0&x2==0&x3==2&x4==0&x5==2&and&x6==1
So, In this case I know that mean2451 comes from the combination
x1==0&x2==0&x3==2&x4==0&x5==2&and&x6==1 from group 1 and I replace its
value for all subjects from group 2 having an identical combination.
This is getting tough, but you have any additional tips, I will be
really
very grateful!
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/