Hey y'all! Apologies in advance if this has been asked, I ran a search and didn't find anything but please feel free to point me in the right direction if needed.
tl;dr: I have data in wide format that I need to reshape into long. The variable names vary by prefix and not by suffix. AFAIK, reshape appears to require static prefixes for the stub and variable suffixes for j. Is there a way to run reshape without having to relabel all my variables?
Longer explanation:
I have data from a randomized vignette survey. Participants answered the same questions about 9 out of 54 possible vignettes. The dataset labels the variables by vignette and then by content, so my variables look like "A1impact A1intent B1impact B1intent A2impact A2intent B2impact B2intent." I would like to reshape from wide to long where "intent" and "impact" are my new variables with rows for A1, A2, B1 and B2. Is this possible? I know my i is PID (participant ID) and my instinct is to make j something like *impact. The closest option I found to that would be @impact but I've run into errors with all of those approaches. Any advice?
Details:
I get the following error when I try @@@outcome or *outcome or ???outcome
I get the following error when I try @outcome
When I try to drop vignette it tells me the variable cannot be found.
Existing Data Structure
Ideal Data Structure
Other helpful info: I'm running v16.1 on a Windows 10 machine.
ETA: Unfortunately the data is confidential and cannot be shared. Please let me know if I can make the example data more helpful! All of the data is numerical with associated labels as appropriate.
tl;dr: I have data in wide format that I need to reshape into long. The variable names vary by prefix and not by suffix. AFAIK, reshape appears to require static prefixes for the stub and variable suffixes for j. Is there a way to run reshape without having to relabel all my variables?
Longer explanation:
I have data from a randomized vignette survey. Participants answered the same questions about 9 out of 54 possible vignettes. The dataset labels the variables by vignette and then by content, so my variables look like "A1impact A1intent B1impact B1intent A2impact A2intent B2impact B2intent." I would like to reshape from wide to long where "intent" and "impact" are my new variables with rows for A1, A2, B1 and B2. Is this possible? I know my i is PID (participant ID) and my instinct is to make j something like *impact. The closest option I found to that would be @impact but I've run into errors with all of those approaches. Any advice?
Details:
I get the following error when I try @@@outcome or *outcome or ???outcome
Code:
. reshape long @@@outcome @@@convince @@@intent @@@impact @@@difftreat @@@power @@@realistic @@@wrong, i(PID) j(vignette) no xij variables found You typed something like reshape wide a b, i(i) j(j). reshape looked for existing variables named a# and b# but could not find any. Remember this picture: long wide +---------------+ +------------------+ | i j a b | | i a1 a2 b1 b2 | |---------------| <--- reshape ---> |------------------| | 1 1 1 2 | | 1 1 3 2 4 | | 1 2 3 4 | | 2 5 7 6 8 | | 2 1 5 6 | +------------------+ | 2 2 7 8 | +---------------+ long to wide: reshape wide a b, i(i) j(j) (j existing variable) wide to long: reshape long a b, i(i) j(j) (j new variable)
Code:
. reshape long @outcome @convince @intent @impact @difftreat @power @realistic @wrong, i(PID) j(vignette) variable vignette contains all missing values r(498);
Existing Data Structure
PID | S1Aimpact | S1Aintent | S1Bimpact | S1Bintent | S2Aimpact | S2Aintent | S2Bimpact | S2Bintent | R1Aimpact | R1Aintent |
1 | 90 | 50 | 100 | 100 | ||||||
2 | 75 | 100 | 20 | 20 | 90 | 100 | ||||
3 | 50 | 75 | 20 | 0 | 100 | 50 | ||||
4 | 20 | 100 | 90 | 0 |
PID | impact | intent | vignette |
1 | 90 | 50 | S1A |
1 | 100 | 100 | S2A |
2 | 75 | 100 | S1B |
2 | 20 | 20 | S2A |
2 | 90 | 100 | R1A |
3 | 50 | 75 | S1A |
3 | 20 | 0 | S2B |
3 | 100 | 50 | R1A |
4 | 20 | 100 | S1A |
4 | 90 | 0 | S2B |
ETA: Unfortunately the data is confidential and cannot be shared. Please let me know if I can make the example data more helpful! All of the data is numerical with associated labels as appropriate.
Comment