I hope all is well. I am trying to perform a reshape, and I cannot quite figure out exactly how to make this work. I am attempting to move my data from a long format to a wide format, and I need this to be done by a specific group.
My data are as follows:
To assist in understanding what I am trying to do, I, manually, created a dataset to show what I need the end product to be. The dataset is as follows:
I have tried the following code, in Stata 15.1, to accomplish this:
When I run this, these are the following errors that I am getting:
In addition, I have developed the analytics, in a specific way, that will require my data be formatted this way. If something like this has been posted elsewhere and I missed it in my search, please, point me in the correct direction. Regardless, will someone help understand how to get the reshape code correct to accomplish this? My research will be able to move forward. Thank you in advance for your time, consideration, and assistance.
My data are as follows:
Code:
* Example generated by -dataex-. To install: ssc install dataex
* dataex id time dyad person condition d partnum obs_id
clear
input int id byte(time dyad person condition) float(d partnum obs_id)
201 1 1 1 1 -7 1 1
202 1 1 2 2 -8 2 1
201 2 1 1 1 -8 1 2
202 2 1 2 2 -1 2 2
203 1 2 1 1 6 1 3
204 1 2 2 2 -4 2 3
203 2 2 1 1 1 1 4
204 2 2 2 2 -3 2 4
205 1 3 1 1 -9 1 5
206 1 3 2 2 -3 2 5
205 2 3 1 1 -6 1 6
206 2 3 2 2 5 2 6
207 1 4 1 1 -2 1 7
208 1 4 2 2 -19 2 7
207 2 4 1 1 1 1 8
208 2 4 2 2 -8 2 8
209 1 5 1 1 10 1 9
210 1 5 2 2 -3 2 9
209 2 5 1 1 8 1 10
210 2 5 2 2 2 2 10
end
Code:
* Example generated by -dataex-. To install: ssc install dataex
*dataex obs_id dyad time condition1 id1 person1 d1 condition2 id2 person2 d2
clear
input float(obs_id dyad time condition1 id1 person1 d1 condition2 id2 person2 d2)
1 1 1 1 201 1 -7 2 202 2 -8
2 1 2 1 201 1 -8 2 202 2 -1
3 2 1 1 203 1 6 2 204 2 -4
4 2 2 1 203 1 1 2 204 2 -3
5 3 1 1 205 1 -9 2 206 2 -3
6 3 2 1 205 1 -6 2 206 2 5
7 4 1 1 207 1 -2 2 208 2 -19
8 4 2 1 207 1 1 2 208 2 -8
9 5 1 1 209 1 10 2 210 2 -3
10 5 2 1 209 1 8 2 210 2 2
end
Code:
reshape wide d, i(obs_id) j(partnum)
- variable id not constant within obs_id
- variable person not constant within obs_id
- variable condition not constant within obs_id
In addition, I have developed the analytics, in a specific way, that will require my data be formatted this way. If something like this has been posted elsewhere and I missed it in my search, please, point me in the correct direction. Regardless, will someone help understand how to get the reshape code correct to accomplish this? My research will be able to move forward. Thank you in advance for your time, consideration, and assistance.
Comment