Bookmark and Share

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: RE: RE: Reshaping data


From   DE SOUZA Eric <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: RE: RE: Reshaping data
Date   Sat, 5 Feb 2011 12:31:49 +0100

I was going to try that when Neil suggestion came in. This works perfectly

insheet using employment.csv, comma
reshape long v, i(region) j(date)
gen year = date +1997
compress
save employment

Eric


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Phil Clayton
Sent: 04 February 2011 23:55
To: [email protected]
Subject: Re: st: RE: RE: Reshaping data

Another option which I think's a little easier is to rename the columns in Excel. For example, rename 2000 to year2000, then (assuming your years are consecutive) just "fill in" the other years by clicking on the bottom right of the year2000 cell and dragging right. Works really well, though to be safe I always create a new row and create the new column names in that rather than overwrite what's already there.

Phil

On 05/02/2011, at 3:11 AM, DE SOUZA Eric wrote:

> Thanks, Neil.
> 
> I had got as far as reshape, and effectively obtained v2 to v12, but missed the last step. Stupid of me. Probably the result of too many students knocking on my door today with questions re: their econometrics project.
> 
> Eric
> 
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Neil 
> Shephard
> Sent: 04 February 2011 16:21
> To: [email protected]
> Subject: Re: st: RE: RE: Reshaping data
> 
> On Fri, Feb 4, 2011 at 3:03 PM, DE SOUZA Eric <[email protected]> wrote:
>> My problem is that the first row is -regionid- -2000- -2001- ...
>> The years are not preceded by letters such as -var- in your example.
>> That's what got me stuck.
>> There are several files of this kind, each of which has to be 
>> converted into a long variable
> 
> So you -insheet- it as usual, and specify the -,header- option, and Stata will look at the header row and go "Hang on a minute, these are illegal variable names, lets call them var2-varN" instead.  You can then reshape as Nick suggested...
> 
> 
>> Assuming say -regionid- -var1980- ... -var2009- this is
>> 
>> reshape long var , i(regionid) j(year)
> 
> ..and to get your years back to what you want you cold then...
> 
> replace year = year + 1998
> 
> ...assuming you've no other variables between the 'regionid' column and the year '2000' column and that there are no missing years (and your brief example suggests this).  If you've got non-continuous years then you might consider using -recode- to recode the default variable names that Stata gives them when -insheet-ing your data to the years they represent.
> 
> You can -reshape- the data without any problems in Stata, its then an issue of keeping track of what you actually want each thing to be labelled/named as.
> 
> Neil
> 
> 
> --
> "Truth in science can be defined as the working hypothesis best suited 
> to open the way to the next better one." - Konrad Lorenz
> 
> Email - [email protected]
> Website - http://kimura.no-ip.org/
> Photos - http://www.flickr.com/photos/slackline/
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index