Q1) I have a following wide data and want to convert into long type.
id | year | quantity | id0 | year0 | quantity0 | id1 | year1 | quantity1 |
1 | 1985 | 100 | 1 | 1986 | 150 | 1 | 1987 | 50 |
2 | 1985 | 200 | 2 | 1986 | 400 | 2 | 1987 | 100 |
3 | 1985 | 300 | 3 | 1986 | 500 | 3 | 1987 | 180 |
id | year | quantity |
1 | 1985 | 100 |
1 | 1986 | 150 |
1 | 1987 | 50 |
2 | 1985 | 200 |
2 | 1986 | 400 |
2 | 1987 | 100 |
3 | 1985 | 300 |
3 | 1986 | 500 |
3 | 1987 | 180 |
So in this case, I don't think simply putting
Code:
reshape long quantity, i(id) j(year)
Should I rename each variable one by one so that it may look like var0, var1, var2,..., var31 before using reshape?
Or is there any better way to do the job?
Q2) If I have multiple (let's say 10) long type data files as above, is it possible to merge all of files with a single line of merge code? Or should I pair and merge them 10 times?
Sorry for bombarding the questions.
Thanks for your help.
0 Response to How to reshape data from wide to long with multiple variables?
Post a Comment