Hi all!
I have a problem in reshaping long a dataset. In particular data look like this, where _03, _06, _09, _12 represent the quarters of a year:
idproduct Other_string_variables sales_03_2004 sales_06_2004 ... sales_12_2015
1 "NAMES" 89 90 12
My aim is to reshape long and obtain something like this:
idproducts quarters sales
1 sales_03_2004 89
1 sales_06_2004 90
1 sales_09_2004 112
1 ....
1 ....
1 sales_12_2015 12
Any idea?
P.s. I have renamed all the variables salesq12004, sales q22004... and then used the code:
But it displays the following error:
variable id does not uniquely identify the observations
Your data are currently wide. You are performing a
reshape long. You specified i(idproduct) and
j(quarter). In the current wide form, variable
idproduct should uniquely identify the observations.
Remember this picture:
Many thanks!
Federico
I have a problem in reshaping long a dataset. In particular data look like this, where _03, _06, _09, _12 represent the quarters of a year:
idproduct Other_string_variables sales_03_2004 sales_06_2004 ... sales_12_2015
1 "NAMES" 89 90 12
My aim is to reshape long and obtain something like this:
idproducts quarters sales
1 sales_03_2004 89
1 sales_06_2004 90
1 sales_09_2004 112
1 ....
1 ....
1 sales_12_2015 12
Any idea?
P.s. I have renamed all the variables salesq12004, sales q22004... and then used the code:
Code:
reshape long sales, i(idproduct) j(quarter) string gen quarter = quarterly(quarter, "QY") format quarter %tq gen Year = year(dofq(quarter)) list
variable id does not uniquely identify the observations
Your data are currently wide. You are performing a
reshape long. You specified i(idproduct) and
j(quarter). In the current wide form, variable
idproduct should uniquely identify the observations.
Remember this picture:
Many thanks!
Federico
Comment