reshapelabel is a program that reshapes a long dataset wide, where the j variable can be a string with spaces (or other characters that are typically not permitted as part of a variable name). The program will encode the entered j variable, generating a temporary numeric variable that gets reshaped. However, the program preserves the original strings in a local and automatically applies them to the new variables' labels. The only restriction for the j variable is now that it must adhere to the restrictions of a variable label.
Here is some example usage of the program.
In an ordinary reshape wide, even after specifying option string, this would have thrown an error, because the j variable (firm) contains spaces, which a variable name cannot have. The code above will produce a dataset with three variables: month, sales1 (labelled as Firm A), sales2 (labelled as Firm B). The code preserves the original sort order, so the entry for "Jan" will be before the entry for "Feb". This program has only been tested on version 18.5 but I suspect it will work on earlier versions that support reshape.
Here is some example usage of the program.
Code:
input str6 firm str3 month int sales "Firm A" "Jan" 10 "Firm A" "Feb" 12 "Firm B" "Jan" 8 "Firm B" "Feb" 9 end reshapelabel, metric(sales) jvar(firm) ivar(month)

Comment