Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: problems with reshaping dataset.
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: problems with reshaping dataset.
Date
Tue, 27 Nov 2012 17:13:11 +0000
You should always show us your code, even if it doesn't work, as then
we can say what you are getting wrong. At a guess the problem here is
turning the corner at century-end. Consider
. list
+-------------------------+
| country v1_99 v1_00 |
|-------------------------|
1. | Albania 1 3 |
2. | Zenda 2 4 |
+-------------------------+
. reshape long v1_ , i(country) string
(note: j = 00 99)
Data wide -> long
-----------------------------------------------------------------------------
Number of obs. 2 -> 4
Number of variables 3 -> 3
j variable (2 values) -> _j
xij variables:
v1_00 v1_99 -> v1_
-----------------------------------------------------------------------------
. l
+--------------------+
| country _j v1_ |
|--------------------|
1. | Albania 00 3 |
2. | Albania 99 1 |
3. | Zenda 00 4 |
4. | Zenda 99 2 |
+--------------------+
. gen year = cond(_j < "20", 2000 + real(_j), 1900 + real(_j))
. l
+---------------------------+
| country _j v1_ year |
|---------------------------|
1. | Albania 00 3 2000 |
2. | Albania 99 1 1999 |
3. | Zenda 00 4 2000 |
4. | Zenda 99 2 1999 |
+---------------------------+
. d
Contains data
obs: 4
vars: 4
size: 72 (99.9% of memory free)
-----------------------------------------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
-----------------------------------------------------------------------------------------------------------------------
country str7 %9s
_j str2 %9s
v1_ byte %8.0g
year float %9.0g
-----------------------------------------------------------------------------------------------------------------------
Sorted by: country _j
Note: dataset has changed since last saved
On Tue, Nov 27, 2012 at 5:02 PM, natasha agarwal
<[email protected]> wrote:
> I have a dataset which looks like:
>
> country v1_80 v2_80...v59_80 v1_00 v2_01 v3_01
> ALB x x x x x x
>
> I use the reshape long comand, but it does not reshape the variables
> where the year is 00, 01.
>
> Besides, I want to reshape the dataset like
>
> country year variable
> ALB 1980 v1
> ALB 1980 v2
> ALB 2000 v1
> ALB 2001 v1
>
> I have tried variants of reshape command but have failed to achieve
> such a structure of my dataset.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/