Hi all,
I am trying to get a local macro that stores the values contained in two string variables in Stata. Normally, this is an easy job using the
command. However, I am now running something where it is important that the local macro does not automatically sort the values. Below, I will do my best to reproduce what my problem is.
Suppose you have the following dataset:
You can generate this data set by doing the following:
As you can see y is simply just a "clean" version of x (lower case everything), remove spaces, remove question marks, etc. When I use the
command to pull the string values into a local macro, I would like the values to be ordered in the same way. Unfortunately,
automatically sorts the values alphabetically, and this results in a different ordering.
For example,
Notice, that because of the capitalization, "deers" gets sorted last in
but gets sorted first in
when everything is lower case. How do I fix this? In other words, I would like two local macros where the two macros will have the same corresponding order. In other words, I would like two local macros:
Is there a way to accomplish this?
Thank you in advance for your help!
Vincent
I am trying to get a local macro that stores the values contained in two string variables in Stata. Normally, this is an easy job using the
Code:
levelsof
Suppose you have the following dataset:
PHP Code:
x y
Do Later dolater
Thank/You thankyou
What? what
Your Welcome yourwelcome
deers deers
Code:
set obs 5 gen x = "Do Later" in 1 replace x = "Thank/You" in 2 replace x = "What?" in 3 replace x = "Your Welcome" in 4 replace x = "deers" in 5 gen y = "dolater" in 1 replace y = "thankyou" in 2 replace y = "what" in 3 replace y = "yourwelcome" in 4 replace y = "deers" in 5
Code:
levelsof
Code:
levelsof
For example,
Code:
. levelsof x `"Do Later"' `"Thank/You"' `"What?"' `"Your Welcome"' `"deers"' . levelsof y `"deers"' `"dolater"' `"thankyou"' `"what"' `"yourwelcome"'
Code:
levelsof x
Code:
levelsof y
Code:
`xvalues' `"Do Later"' `"Thank/You"' `"What?"' `"Your Welcome"' `"deers"' `yvalues' `"dolater"' `"thankyou"' `"what"' `"yourwelcome"' `"deers"'
Thank you in advance for your help!
Vincent
Comment