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: st: list x matrix


From   richard boylan <[email protected]>
To   [email protected]
Subject   Re: st: list x matrix
Date   Sat, 27 Mar 2010 15:56:31 -0500

I had thought of doing that, but was wondering if there was a more
direct way of doing that.

So, I guess that answer the question, one cannot do this without
converting the data into matrix and then back into variable.

On Sat, Mar 27, 2010 at 3:35 PM, Scott Merryman
<[email protected]> wrote:
> You could use -mkmat- to convert the x variables to matrix, perform
> the multiplication and then use -svmat- to create the  variables from
> matrix.
>
> For example:
>
>
> . sysuse auto,clear
> (1978 Automobile Data)
>
> . matrix b = 10, 2, -3
> . mkmat mpg price, mat(X)
> . count
>   74
> . mat X = J(r(N),1,1), X
> . matrix z = X*b'
> . svmat z
>
>
> Scott
>
> On Sat, Mar 27, 2010 at 2:49 PM, richard boylan <[email protected]> wrote:
>> Very simple question, but I couldn't find the answer in the STATA documentation.
>>
>> I have a list
>> local var "x1 x2 x3 ...."
>>
>> and a 1 x n matrix (vector)
>>
>> b = (b1 b2 b3 ..)
>>
>> How do I compute the new variable
>>
>> z = b1*x1 + b2*x2 + b3*x3  + ...
>>
>> I mean I know how to do that by writing the sum, there just has to be
>> a better way of doing this.
>>
>> Also, what it is the best place to figure out this stuff?
>>
>> Thanks.
>>
>> Richard
>> *
>> *   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/
>

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index