You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cool pset question from Ellen: calculate a number of means but only wants to output the biggest 3. Solution: loop through, calculate means, put all in a local, then use extended macro fcn to sort the local and only output first 3 from it.
The text was updated successfully, but these errors were encountered:
. loc list 1 4 9 16
. loc sort : list sort list
. di "`sort'"
1 16 4 9
You could put it in a matrix, but I don't think there's an easy way to sort Stata matrices. You could convert the matrix to a Stata dataset using svmat, or create a dataset along the way using post. Or there's Mata.
Thanks @matthew-white - having a discussion on this now. Couldn't you just create a new variable, calculate the means and impute them into separate observations of the new variable. Then just sort the new variables and use, say, explicit subcripting to output top 3? I feel Python might be a better solution here!
Yeah, any language that easily allows multiple datasets would probably be better! You could create the new variable as long as there are enough observations. (You could try to find the mean of 100 variables in a dataset with 10 observations, in which case this wouldn't work.)
Cool pset question from Ellen: calculate a number of means but only wants to output the biggest 3. Solution: loop through, calculate means, put all in a local, then use extended macro fcn to sort the local and only output first 3 from it.
The text was updated successfully, but these errors were encountered: