(1) I have a piece of code which I think is probably pretty inefficient and I was wondering
whether there is a more efficient alternative. I want to have the log of the median of w
conditional on an indicator being set on (denoted as I0, I1, or I2) saved in a scalar variable. I
did this by creating a variable denoting the median and then just setting using the first entry of
this temporary variable as the scalar and then using that next value to get the log. I think
this is probably really roundabout and not taking advantage of stata's capabilities. thanks!
Right now, the code looks like:
tempvar temp`i'
egen `temp`i''=median(`w') if `I`i''
gsort -`I`i''
*note, the reason this works is because this will always be the first observation after doing the
sort, and locals get the first value of variable..TRICKY..
local tempweird=`temp`i''
*THIS IS THE MAIN DEFINITION LINE RIGHT HERE
scalar lw`i'=log(`tempweird')
(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: