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]

st: RE: Problems with the reshape command


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Problems with the reshape command
Date   Wed, 19 Jan 2011 17:20:52 +0000

I think the problems are in your data -- and not at all with the -reshape- command. 

The first two observations are duplicates even on -port- and -item-, so two data values would be fighting to fit within the same cell! 

And this problem occurs elsewhere in this dataset. 

So, on the evidence available, these data are not suitable for -reshape-. 

Otherwise put, your cross-tabulation is _not_ something that -reshape- will ever produce. It does not encompass the idea that categories can be repeated, as they are on the rows of your table. 

I don't know what you want to do eventually with these data, but it may be that some kind of -collapse- to averages or other summaries is needed first. The idea of a item * port cross-tabulation doesn't mesh with -reshape- otherwise. 

Nick 
[email protected] 

Syed Basher

I am using Stata 11.1.  I have the following hypothetical data:

     +--------------------------+
      | port       item     price      |
      |--------------------------|
  1. |        3    4029   27.62  |
  2. |        3    4029   15.47  |
  3. |        1    1006   37.55  |
  4. |        3    2045   15.18  |
  5. |        1    2045   16.21  |
      |------------------------|
  6. |        1    4061   92.79 |
  7. |        2    8041   12.55 |
  8. |        2    2011   89.68 |
  9. |        3    7031   68.01 |
10. |        2    2011   13.13 |
      |-----------------------|

I would like to reshape the data to wide format using:
. reshape wide price, i(port) j(item)

This is of course problematic in Stata since "item" is not unique within 
"port".  Eventually I would like to obtain the following cross-tab (in wide 
format):

port |       1006     2011     2045     4029     4061     7031     8041   
-------------------------------------------------------------------
1     |        37.55                16.21                 92.79
2     |                   
89.68                                                        12.55
2     |                   13.33
3     |                                15.18     27.62                  68.01
3     |                                              15.47

I have been consulting Stata's FAQs on this issue 
(http://www.stata.com/support/faqs/data/reshape3.html) without much success.  I 
hope you can help me.

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