Hello everyone,
I did stumble upon a new problem with my current dataset, which has a much more complicated wide format than I am used to. Maybe some of you allready did have such an odd case of wide data and know how to help.
I do have the following difficulties:
In the end, I want the long data look like this:
So using the STATA-FAQ-Link above, I tried this which gives me an error:
Any Ideas how to reshape this? Any help and hint is highly appreciated. I never had to reshape such an odd structure before.
Additional Question: In the example above I did have to specifiy the Measurement-Names "Meas0010", "Meas0020" and "Meas0020A". Is it possible, to automate this as well? All Measurement Names start with the Keyword "Meas", so the Variablenames are always of the structure "IDMeasMeasurement-Name", e.g. "A101Meas0020A" stands for ID = "A101" and Measurement = "Meas0020A".
Cheers,
Jonathan
I did stumble upon a new problem with my current dataset, which has a much more complicated wide format than I am used to. Maybe some of you allready did have such an odd case of wide data and know how to help.
I do have the following difficulties:
- I have no identifier Variable for the Wide Variables.
- My Dataset is quite wide. I do have about 7000 Variables.
- The number of variables per ID is not constant, so for some IDs I have 5 and for others I have 10 variables.
Code:
clear input str45 Year "2010" "2011" "2012" "2014" end input str45 A101Meas0010 "1.50" "1.70" "1.71" "1.71" input str45 A101Meas0020 "50" "60" "65" "64" input str45 A101Meas0020A "51" "62" "64" "68" input str45 FE123Meas0010 "1.60" "1.75" "1.92" "1.94" input str45 FE123Meas0020 "60" "72" "88" "92" list +-------------------------------------------------------------+ | Year A10~0010 A10~0020 A1~0020A FE1~0010 FE1~0020 | |-------------------------------------------------------------| 1. | 2010 1.50 50 51 1.60 60 | 2. | 2011 1.70 60 62 1.75 72 | 3. | 2012 1.71 65 64 1.92 88 | 4. | 2014 1.71 64 68 1.94 92 | +-------------------------------------------------------------+
Code:
+--------------------------------------------------+ | Year ID Meas0010 Meas0020 Meas0020A | |--------------------------------------------------| 1. | 2010 A101 1.50 50 . | 2. | 2010 FE123 1.60 51 60 | 3. | 2011 A101 1.70 60 . | 4. | 2011 FE123 1.75 62 72 | 5. | 2012 A101 1.71 65 . | 6. | 2012 FE123 1.92 64 88 | 7. | 2014 A101 1.71 64 . | 8. | 2014 FE123 1.94 68 92 | +--------------------------------------------------+
Code:
unab vars : *Meas* local stubs : subinstr local vars "Meas0010" "", all local stubs : subinstr local stubs "Meas0020" "", all local stubs : subinstr local stubs "Meas0020A" "", all reshape long "`stubs'", i(Year) j(Measurement) string (note: j = Meas0010 Meas0020 Meas0020A) (note: A101AMeas0010 not found) variable A101Meas0010 not found r(111);
Additional Question: In the example above I did have to specifiy the Measurement-Names "Meas0010", "Meas0020" and "Meas0020A". Is it possible, to automate this as well? All Measurement Names start with the Keyword "Meas", so the Variablenames are always of the structure "IDMeasMeasurement-Name", e.g. "A101Meas0020A" stands for ID = "A101" and Measurement = "Meas0020A".
Cheers,
Jonathan
Comment