Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: dot product across many variables


From   Paul Burkander <paul@burkander.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: dot product across many variables
Date   Tue, 29 Nov 2011 13:11:47 -0500

ah, that's great.  Much better than having to learn mata in day.

Thanks!

On Tue, Nov 29, 2011 at 1:03 PM, Nick Cox <njcoxstata@gmail.com> wrote:
> Consider a loop
>
> gen newdummy = 0
>
> forval j = 2000/2010 {
> replace newdummy = newdummy + firstdummy`j' * seconddummy`j'
> }
>
> On Tue, Nov 29, 2011 at 5:11 PM, Paul Burkander <paul@burkander.com> wrote:
>
>> I have a data set that has two binary variables in each of several
>> years.  I'd like to create a new variable that is the sum across all
>> years of the product of the two within year.
>>
>> For example,
>> firstdummy2000=1
>> seconddummy2000=0
>> firstdummy2001=1
>> seconddummy2001=1
>>
>> newdummy=(firstdummy2000*seconddummy2000+firstdummy2001*seconddummy2001)=1
>>
>> There are so many years that it seems cumbersome to do it as above,
>> moreover the years might change over time and I'd like to be flexible.
>>
>> I thought perhaps a matrix command would work, doing a dot product?
>>
>
> *
> *   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/

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


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index