Never just say that something "didn't work". Say exactly what happened (in this case, give the error message) and explain why it is not you want.
In your case 2012
and 2013
cannot possibly be Stata variable names, as no Stata variable name can start with a number. If 2012
were an allowed variable name, how could Stata possibly tell whether 2012
meant itself or the variable with the same name? (Perhaps 2012
and 2013
are variable labels, but reshape
does not work with variable labels.)
In any case, reshape
should not be fed variable names. It needs stubs, as is documented in the help.
We can't see your variable names. Suppose you have v2012
and v2013
.
clear
input str3 Company str4 Item v2012 v2013
ABD TA 100 110
ABD EBIT 200 220
JKL TA 115 120
JKL EBIT 250 270
end
reshape long v , i(Company Item) j(Year)
list
+-----------------------------+
| Company Item Year v |
|-----------------------------|
1. | ABD EBIT 2012 200 |
2. | ABD EBIT 2013 220 |
3. | ABD TA 2012 100 |
4. | ABD TA 2013 110 |
|-----------------------------|
5. | JKL EBIT 2012 250 |
6. | JKL EBIT 2013 270 |
7. | JKL TA 2012 115 |
8. | JKL TA 2013 120 |
+-----------------------------+
reshape wide v, i(Company Year) j(Item) string
renpfix v
list
+-----------------------------+
| Company Year EBIT TA |
|-----------------------------|
1. | ABD 2012 200 100 |
2. | ABD 2013 220 110 |
3. | JKL 2012 250 115 |
4. | JKL 2013 270 120 |
+-----------------------------+
Note further twists to your problem. i(Company)
would not have worked any way, as there are multiple observations for each identifier. You need two calls to reshape
as a long
is needed to get different years as observations and a wide
is needed to get different items as variables.
The frequent need for a double reshape
is documented in this FAQ: a search reshape
in Stata would have pointed you towards it.
Evidently your syntax will differ if your variable names differ. As also documented in the FAQ just cited, you may need to rename
your variables before a reshape
is possible.
NB: As edited, the program is called Stata and has been for almost its entire history of 30 years. Any source telling you otherwise is not authoritative.