Bookmark and Share

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: [SPAM] Re: Re: [SPAM] Re: st: sum the variable based on other variables


From   wanhaiyou <[email protected]>
To   [email protected]
Subject   Re: [SPAM] Re: Re: [SPAM] Re: st: sum the variable based on other variables
Date   Tue, 25 Mar 2014 19:49:19 +0800 (GMT+08:00)

Hi,Nick,
Yes,the codes are working well following your suggestion.
You code is perfect!
Many thanks for your help


Bests,
wanhaiyou
Hunan university

> -----原始邮件-----
> 发件人: "Nick Cox" <[email protected]>
> 发送时间: 2014-03-25 19:50:27 (星期二)
> 收件人: "[email protected]" <[email protected]>
> 抄送: 
> 主题: [SPAM] Re: Re: [SPAM] Re: st: sum the variable based on other variables
> 
> It worked for me. Make sure all the code is in one place, e.g. the
> do-file editor.
> Nick
> [email protected]
> 
> 
> On 25 March 2014 11:19, wanhaiyou <[email protected]> wrote:
> > Hi,Nick
> > Thanks very much for your suggestion.
> > However,the following codes are not work well on my computer
> >
> > clear
> > input v1 v2 v3
> > 1 1 0
> > 0 0 1
> > 1 0 1
> > 1 1 1
> > 0 1 0
> > 1 1 1
> > end
> >
> > tempname handle
> >
> > postfile `handle' str32 which1 str32 which2 mean using myresults, replace
> >
> > . forv i=1/3 {
> >   2.   forv j=1/3 {
> >   3.   if `i'~=`j' {
> >   4.     sum  v`i' if v`i' == v`j', meanonly
> >   5.     post `handle' ("v`i'") ("v`j'") (`r(mean)')
> >   6.
> > . }
> >   7. }
> >   8. }
> > ( invalid name
> > r(198);
> >
> > I have looked at the help for postfile,but I cannot find the reason.
> > How to fix this error?
> >
> > Many thanks for your help again
> >
> > Bests,
> > wanhaiyou
> > Hunan University
> >
> >> -----原始邮件-----
> >> 发件人: "Nick Cox" <[email protected]>
> >> 发送时间: 2014-03-25 18:28:56 (星期二)
> >> 收件人: "[email protected]" <[email protected]>
> >> 抄送:
> >> 主题: Re: [SPAM] Re: st: sum the variable based on other variables
> >>
> >> Look at the help for -postfile-.
> >>
> >> Something like
> >>
> >> clear
> >> input v1 v2 v3
> >> 1 1 0
> >> 0 0 1
> >> 1 0 1
> >> 1 1 1
> >> 0 1 0
> >> 1 1 1
> >> end
> >>
> >> tempname handle
> >>
> >> postfile `handle' str32 which1 str32 which2 mean using myresults, replace
> >>
> >> forv i=1/3 {
> >>   forv j=1/3 {
> >>   if `i'~=`j' {
> >>     sum  v`i' if v`i' == v`j', meanonly
> >>     post `handle' ("v`i'") ("v`j'") (`r(mean)')
> >>
> >> }
> >> }
> >> }
> >>
> >> postclose `handle'
> >>
> >> use myresults, clear
> >>
> >> Nick
> >> [email protected]
> >>
> >>
> >> On 25 March 2014 09:58, wanhaiyou <[email protected]> wrote:
> >> > Nick,thanks very much.
> >> > In fact, I only need the mean.
> >> > I attemp to save these value as a matrix.However,when the number of variable large,e.g.,100,
> >> > the method is unfeasible.
> >> > The following codes
> >> > **
> >> > clear
> >> > input v1 v2 v3
> >> > 1 1 0
> >> > 0 0 1
> >> > 1 0 1
> >> > 1 1 1
> >> > 0 1 0
> >> > 1 1 1
> >> > end
> >> >
> >> > forv i=1/3 {
> >> >   forv j=1/3 {
> >> >   if `i'~=`j' {
> >> >     sum  c`i' if c`i'==c`j', meanonly
> >> >         mat b=(nullmat(b)\r(mean))
> >> > }
> >> > }
> >> > }
> >> >
> >> > How could I save those value (r(mean) from "sum"
> >> > as a column?
> >> >
> >> >
> >> > Bests,
> >> > wanhaiyou
> >> > Hunan University
> >> >
> >> >
> >> >> -----原始邮件-----
> >> >> 发件人: "Nick Cox" <[email protected]>
> >> >> 发送时间: 2014-03-25 17:01:06 (星期二)
> >> >> 收件人: "[email protected]" <[email protected]>
> >> >> 抄送:
> >> >> 主题: [SPAM] Re: st: sum the variable based on other variables
> >> >>
> >> >> You are using -egen- to create variables, each of which just holds a
> >> >> constant. That is not necessary. The sum is left in memory as r(sum)
> >> >> after -summarize-.
> >> >>
> >> >> I don't know what you want to do with your millions of sums, so this
> >> >> code is only a start.
> >> >>
> >> >> forv i=1/3 {
> >> >>   forv j=1/3 {
> >> >>   if `i'~=`j' {
> >> >>     sum  v`i' if v`i'==v`j', meanonly
> >> >>     di r(sum)
> >> >> }
> >> >> }
> >> >> }
> >> >>
> >> >> Nick
> >> >> [email protected]
> >> >>
> >> >> On 25 March 2014 04:19, wanhaiyou <[email protected]> wrote:
> >> >>
> >> >> > 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.
> >> >> *
> >> >> *   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/
> >> >
> >> >
> >> > --
> >> > 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/
> >>
> >> *
> >> *   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/
> >
> >
> > --
> > 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/
> 
> *
> *   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/


--
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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index