Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

201 Pset question #35

Open
hdiamondpollock opened this issue Dec 10, 2014 · 3 comments
Open

201 Pset question #35

hdiamondpollock opened this issue Dec 10, 2014 · 3 comments
Labels

Comments

@hdiamondpollock
Copy link
Contributor

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.

@matthew-white
Copy link

:list sort sorts a macro as a string! E.g.:

. 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.

@hdiamondpollock
Copy link
Contributor Author

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!

@matthew-white
Copy link

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants