# st: Re: efficiency of coding

 From "Michael Blasnik" <[email protected]> From "NEYMOTIN, FLORENCE" <[email protected]> To <[email protected]> To <[email protected]> Subject st: Re: efficiency of coding Subject st: efficiency of coding Date Sun, 17 Jul 2005 21:36:13 -0400

```I have two questions for you:
```
```<snip>
```
```----------------------------------------------------------------
forvalues i=0(1)2 {
tempvar temp`i'
egen `temp`i''=median(`w') if `I`i''
gsort -`I`i''
local tempweird=`temp`i''
scalar lw`i'=log(`tempweird')
```
```<snip>
}

Why not avoid creating the variables?
sum `w' if  `I`i'',detail
scalar lw`i'=r(p50)

```
(2) If I have two matrices A and B, where A is 15x3, and B is 15x1, and I want to make the third column of A EQUAL to the B matrix, is there a quick way to do this? Right now, I have it replacing value by value in the matrix but I think this is probably slower than it could be.
The code now looks like:

forvalues i=1(1)15{
matrix A[`i' , 3]= B[`i',1]
}
----------------------------------------------------------------
Florence

It depends on whether A already has a thrid column, sort of. If there is no third column, then you can :

mat A=A,B

otherwise

mat A=A[1...,1..2] , B

You really should just read the on-line help. whelp matrix would be a good start

Michael Blasnik
[email protected]

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/