Reshaping Panel Data (long to wide)

brian_griffin

New Member
Joined
Oct 30, 2012
Messages
7
Hello,

I would like to transform and reshape my data set from the long to the wide format.

Unluckily, in the original data set the variables are listed below each other in one column.

The orignal data set has the following format :
IDVARYearValue
1A20105
1A20119
1A20127
2A20103
2A20112
2A20128
3A20104
3A20112
3A20121
1B20103
1B20114
3B20105
3B20118
3B20121
2C20102
2C20113
2C20124

<tbody>
</tbody>


I would to like to transform the data to the following format:
IDYearABC
1201053
1201194
120127
2201032
2201123
2201284
3201045
3201128
3201211

<tbody>
</tbody>


Is there any feasible way to achieve this ?

I do not have any idea how to proceed. :(

Thanks in advance,
Brian
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Can't you use a Pivot Table?


Excel 2003
FGHIJ
1Sum of ValueVAR
2IDYearBAC
31201035
4201149
520127
62201032
7201123
8201284
93201054
10201182
11201211
Sheet2
 
Upvote 0
Try this:-
Results start "F1"
Code:
[COLOR="Navy"]Sub[/COLOR] MG22Nov14
[COLOR="Navy"]Dim[/COLOR] Rng         [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Dn          [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] n           [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Col         [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]Dim[/COLOR] twn         [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] c           [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
ReDim Ray(1 To Rng.Count, 1 To 5)
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    twn = Dn & Dn.Offset(, 2)
    Col = Asc(Dn.Offset(, 1)) - 62
    [COLOR="Navy"]If[/COLOR] Not .Exists(twn) [COLOR="Navy"]Then[/COLOR]
        n = n + 1
        .Add twn, n
        Ray(n, 1) = Dn: Ray(n, 2) = Dn.Offset(, 2)
        Ray(n, Col) = Dn.Offset(, 3)
    [COLOR="Navy"]Else[/COLOR]
        Ray(.Item(twn), Col) = Dn.Offset(, 3)
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
c = .Count
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]With[/COLOR] Range("F1")
.Resize(, 5) = Array("ID", "Year", "A", "B", "C")
.Offset(1).Resize(c, 5) = Ray
[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top