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]
st: sum the variable based on other variables
From
wanhaiyou <[email protected]>
To
[email protected]
Subject
st: sum the variable based on other variables
Date
Tue, 25 Mar 2014 12:19:04 +0800 (GMT+08:00)
Hi,Statalist,
I want to creat the sum of one variable based on other variables.For example,
I have the following dataset
v1 v2 v3
1 1 0
0 0 1
1 0 1
1 1 1
0 1 1
0 1 0
If v1=v2, then sum the corresponding value of v1
v1 v2
1 1 equal
0 0 equal
1 0 not equal
1 1 equal
0 1 not equal
0 1 not equal
if v1=v3, then sum the corresponding value of v1
....
if v3==v1,then sum the corresponding value of v3
if v3=v2,then sum the corresponging value of v3
I have written the following codes
forv i=1/3 {
forv j=1/3 {
if `i'~=`j' {
egen vsum`i'`j'=total(v`i') if v`i'==v`j'
}
}
}
However, I have 5000 variables but the max number of variables is 32,767.
Therefore, this codes cannot be used.
Any suggestions will be appreciated!
--
Bests,
wanhaiyou
Hunan University
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/