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: AW: AW: st: AW: Reshaping a Dataset


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: AW: AW: st: AW: Reshaping a Dataset
Date   Fri, 23 Jul 2010 19:36:23 +0100

I don't know what you tried with -reshape- but this data structure needs some surgery before anything very much Stataish is possible. Here's my code. (No email from me from now until Sunday.) 

forval j = 2/8 { 
        local site`j'  = v`j'[1]
        local county`j' = v`j'[2]
}
drop in 1/3
destring v2-v8, replace
rename v1 date
reshape long v, i(date)
rename _j county
clonevar site = county
forval j = 2/8 {
label def site `j' "`site`j''", add
label def county `j' "`county`j''", add
}
label val county county
label val site site
rename v conc

Nick 
[email protected] 

[email protected]

Sorry for the delay, I was pulled into a meeting.

. desc

Contains data
  obs:           150                          
 vars:             8                          
 size:        14,100 (99.9% of memory free)
------------------------------------------------------------------------------------------
              storage  display     value
variable name   type   format      label      variable label
------------------------------------------------------------------------------------------
v1              str8   %9s                    
v2              str7   %9s                    
v3              str11  %11s                   
v4              str11  %11s                   
v5              str11  %11s                   
v6              str12  %12s                   
v7              str10  %10s                   
v8              str20  %20s                   
------------------------------------------------------------------------------------------
Sorted by:  
     Note:  dataset has changed since last saved

. li in 1/5

     +-----------------------------------------------------------------------------------------+
     |       v1        v2         v3         v4            v5         v6           v7       v8 |
     |-----------------------------------------------------------------------------------------|
  1. |     site    Crouse   Garinger   Arrowood   County Line   Rockwell   Enochville   Monroe |
  2. |   county   Lincoln     Burton     Burton        Burton     Chance       Chance    Union |
  3. |     date                                                                                |
  4. | 20050701                0.082                    0.083                    0.08          |
  5. | 20050709                0.076                                            0.076          |
     +-----------------------------------------------------------------------------------------+

-----Original Message-----
>From: Martin Weiss <[email protected]>
>Sent: Jul 23, 2010 11:50 AM
>To: [email protected]
>Subject: AW: AW: st: AW: Reshaping a Dataset
>
>
><> 
>
>
>Reg should also answer the questions raised by Nick a couple of hours ago. It will only take him a couple of seconds to do so, I guess...
>
>
>
>HTH
>Martin
>
>
>-----Ursprüngliche Nachricht-----
>Von: [email protected] [mailto:[email protected]] Im Auftrag von [email protected]
>Gesendet: Freitag, 23. Juli 2010 16:55
>An: [email protected]
>Betreff: Re: AW: st: AW: Reshaping a Dataset
>
>This is a dataset that I received in Excel from an engineer in another section of our office. The data are airborne concentrations measured at several sites over several dates. The data set covers the period 2005 - 2009. There are over 500 lines of data, and the thought of having to rearrange these manually is, well, very unpleasant.
>
>reg
>
>
>-----Original Message-----
>>From: Martin Weiss <[email protected]>
>>Sent: Jul 23, 2010 10:32 AM
>>To: [email protected]
>>Subject: AW: st: AW: Reshaping a Dataset
>>
>>
>><> 
>>
>>
>>Begs the question: How come the data are organized in this fashion? I would not know how to conduct an analysis given such a data structure. Maybe you can fill us in.
>>
>>
>>
>>HTH
>>Martin
>>
>>
>>-----Ursprüngliche Nachricht-----
>>Von: [email protected] [mailto:[email protected]] Im Auftrag von [email protected]
>>Gesendet: Freitag, 23. Juli 2010 15:06
>>An: [email protected]
>>Betreff: Re: st: AW: Reshaping a Dataset
>>
>>Yes, that is correct.
>>
>>
>>-----Original Message-----
>>>From: Martin Weiss <[email protected]>
>>>Sent: Jul 23, 2010 8:55 AM
>>>To: [email protected]
>>>Subject: st: AW: Reshaping a Dataset
>>>
>>>
>>><> 
>>>
>>>The first table does not wrap well, so it is hard to tell what the -varname-s really are. It looks as if the columns contain both strings, to hold the site and county names, and numeric data, correct?
>>>
>>>
>>>
>>>HTH
>>>Martin
>>>
>>>
>>>-----Ursprüngliche Nachricht-----
>>>Von: [email protected] [mailto:[email protected]] Im Auftrag von [email protected]
>>>Gesendet: Freitag, 23. Juli 2010 14:47
>>>An: Statalist
>>>Betreff: st: Reshaping a Dataset
>>>
>>>I've been working on this for a while now, but obviously I do not yet understand what -reshape- needs to do its work.
>>>
>>>Here is some data from the dataset:
>>>
>>>site	  Crouse   Garinger   Arrowood   County Line   Rockwell   Enochville   Monroe
>>>county	  Lincoln  Burton     Burton     Burton        Chance     Chance       Union
>>>date							
>>>20050701	    0.082	           0.083                    0.08	
>>>20050709            0.076      0.076	
>>>20050720            0.084                               0.079			
>>>20050721                       0.08        0.085			
>>>20050722						0.078	
>>>20050724						0.08	
>>>20050725  0.101     0.081      0.095       0.078        0.087       0.079
>>>
>>>I want to reshape the dataset to look like:
>>>
>>>date      county     site           conc
>>>20050701  Lincoln    Crouse           .
>>>20050701  Burton     Garinger       0.082
>>>20050701  Burton     Arrowood         .
>>>20050701  Burton     County Line    0.083
>>>20050701  Chance     Rockwell         .
>>>20050701  Chance     Enochville      0.08
>>>20050701  Union      Monroe           .
>>>etc.  etc.
>>>
>>>Can anyone assist me with this? Thanks much.

*
*   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