reshape command error

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

reshape command error

Selameab, Tehout
Hello Stata users:
 
I'm not very experienced in STATA; trying to learn it. I cannot see the problem with my reshape command. I have a dataset with multiple rows per id. Each client has unique problem types (this is a social services dataset). I want to reshape the dataset into one row per client.
 
 
My data looks like this:
 
Id probnum obs
1 1 1
1 12 2
1 14 3
1 39 4
1 40 5
1 49 6
 
My code is this:
reshape wide probnum, i(fid) j(obs)

I keep getting the error message: problem not constant within id.
What am I missing?!

Many thanks,
Tehout

*
*   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/
Reply | Threaded
Open this post in threaded view
|

Re: reshape command error

Sergiy Radyakin
Check for typos: what is fid?
Assuming it is "Id" the code works (Stata 11/Windows)
Best, Sergiy Radyakin

. clear

. input Id probnum obs

            Id    probnum        obs
  1. 1       1               1
  2. 1       12              2
  3. 1       14              3
  4. 1       39              4
  5. 1       40              5
  6. 1       49              6
  7. end

.
. reshape wide probnum, i(Id) j(obs)
(note: j = 1 2 3 4 5 6)

Data                               long   ->   wide
-----------------------------------------------------------------------------
Number of obs.                        6   ->       1
Number of variables                   3   ->       7
j variable (6 values)               obs   ->   (dropped)
xij variables:
                                probnum   ->   probnum1 probnum2 ... probnum6
-----------------------------------------------------------------------------

.
end of do-file

. l

     +----------------------------------------------------------------------+
     | Id   probnum1   probnum2   probnum3   probnum4   probnum5   probnum6 |
     |----------------------------------------------------------------------|
  1. |  1          1         12         14         39         40         49 |
     +----------------------------------------------------------------------+





On Tue, Nov 16, 2010 at 3:44 PM, Selameab, Tehout
<[hidden email]> wrote:

> Hello Stata users:
>
> I'm not very experienced in STATA; trying to learn it. I cannot see the problem with my reshape command. I have a dataset with multiple rows per id. Each client has unique problem types (this is a social services dataset). I want to reshape the dataset into one row per client.
>
>
> My data looks like this:
>
> Id      probnum obs
> 1       1               1
> 1       12              2
> 1       14              3
> 1       39              4
> 1       40              5
> 1       49              6
>
> My code is this:
> reshape wide probnum, i(fid) j(obs)
>
> I keep getting the error message: problem not constant within id.
> What am I missing?!
>
> Many thanks,
> Tehout
>
> *
> *   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/
Reply | Threaded
Open this post in threaded view
|

RE: reshape command error

Nick Cox
I agree with Sergiy: The code looks fine. I guess the problem lies in the part of the data you are not showing us.

Nick
[hidden email]

Sergiy Radyakin

Check for typos: what is fid?
Assuming it is "Id" the code works (Stata 11/Windows)

. clear

. input Id probnum obs

            Id    probnum        obs
  1. 1       1               1
  2. 1       12              2
  3. 1       14              3
  4. 1       39              4
  5. 1       40              5
  6. 1       49              6
  7. end

.
. reshape wide probnum, i(Id) j(obs)
(note: j = 1 2 3 4 5 6)

Data                               long   ->   wide
-----------------------------------------------------------------------------
Number of obs.                        6   ->       1
Number of variables                   3   ->       7
j variable (6 values)               obs   ->   (dropped)
xij variables:
                                probnum   ->   probnum1 probnum2 ... probnum6
-----------------------------------------------------------------------------

.
end of do-file

. l

     +----------------------------------------------------------------------+
     | Id   probnum1   probnum2   probnum3   probnum4   probnum5   probnum6 |
     |----------------------------------------------------------------------|
  1. |  1          1         12         14         39         40         49 |
     +----------------------------------------------------------------------+


Selameab, Tehout

I cannot see the problem with my reshape command. I have a dataset with multiple rows per id. Each client has unique problem types (this is a social services dataset). I want to reshape the dataset into one row per client.

>
>
> My data looks like this:
>
> Id      probnum obs
> 1       1               1
> 1       12              2
> 1       14              3
> 1       39              4
> 1       40              5
> 1       49              6
>
> My code is this:
> reshape wide probnum, i(fid) j(obs)
>
> I keep getting the error message: problem not constant within id.
> What am I missing?!

*
*   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/
Reply | Threaded
Open this post in threaded view
|

reshape command error

Selameab, Tehout
In reply to this post by Selameab, Tehout
Thank you for your response Sergiy. Obviously, it worked for you! Still
can't get it to work on my laptop. Will try another PC, although that
shouldn't make a difference. I'm using Stata11/Windows on both laptop
and desktop.

Thanks again,
Tehout



*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: reshape command error

Jason Becker
Hi Tehout,

Might I recommend a few troubleshooting tips before switching machines?

First, use Sergiy's code to produce a simplified data set and see if the
command works then as written (pasted below for convenience):
. clear

. input Id probnum obs

            Id    probnum        obs
  1. 1       1               1
  2. 1       12              2
  3. 1       14              3
  4. 1       39              4
  5. 1       40              5
  6. 1       49              6
  7. end

.
. reshape wide probnum, i(Id) j(obs)


If that works, then it is almost certain that your install, computer,
etc are not at issue and Nick is almost certainly right-- there is a
peculiar observation or structure in your data which does not fit the
simplified view you're presenting.  At this stage, I might split my data
set into say, 10, 50, or 100 observation chunks and try running the
reshape on several of those.  I suspect that it will execute perfectly
on most but occasional get caught.  When you get tossed back the same
error again, look at the structure of those observations and if you
can't figure out what's wrong, repost data that looks closer to that
form and we can help out better.
___________________________________
Jason Becker
Research Specialist
Office of Data Analysis and Research
Rhode Island Department of Education
255 Westminster Street Providence, RI 02903
(401)-222-8495

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Selameab,
Tehout
Sent: Wednesday, November 17, 2010 10:28 AM
To: [hidden email]
Subject: st: reshape command error

Thank you for your response Sergiy. Obviously, it worked for you! Still
can't get it to work on my laptop. Will try another PC, although that
shouldn't make a difference. I'm using Stata11/Windows on both laptop
and desktop.

Thanks again,
Tehout



*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: RE: reshape command error

Nick Cox
I agree with Jason that checking different machines, installations, etc., is most unlikely to illuminate the problem here, and I agree with him agreeing with me that the issue is the data.

The assumption appears to be that the triples -Id probnum obs- are all distinct (some say unique). If so, -isid- or -duplicates- provides a one-line test.

Nick
[hidden email]

Jason Becker

Might I recommend a few troubleshooting tips before switching machines?

First, use Sergiy's code to produce a simplified data set and see if the
command works then as written (pasted below for convenience):
. clear

. input Id probnum obs

            Id    probnum        obs
  1. 1       1               1
  2. 1       12              2
  3. 1       14              3
  4. 1       39              4
  5. 1       40              5
  6. 1       49              6
  7. end

.
. reshape wide probnum, i(Id) j(obs)


If that works, then it is almost certain that your install, computer,
etc are not at issue and Nick is almost certainly right-- there is a
peculiar observation or structure in your data which does not fit the
simplified view you're presenting.  At this stage, I might split my data
set into say, 10, 50, or 100 observation chunks and try running the
reshape on several of those.  I suspect that it will execute perfectly
on most but occasional get caught.  When you get tossed back the same
error again, look at the structure of those observations and if you
can't figure out what's wrong, repost data that looks closer to that
form and we can help out better.

Selameab, Tehout

Thank you for your response Sergiy. Obviously, it worked for you! Still
can't get it to work on my laptop. Will try another PC, although that
shouldn't make a difference. I'm using Stata11/Windows on both laptop
and desktop.


*
*   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/
Reply | Threaded
Open this post in threaded view
|

reshape command error

Selameab, Tehout
In reply to this post by Selameab, Tehout
It worked, finally! It worked on my desktop (but wouldn't work on my
laptop). No idea why! Just happy it worked and I can move on with my
work!

Thanks again.
Tehout


*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: reshape command error

Nick Cox
This is good news for you, but still worrying. Something must be different: either the dataset or your Stata installation.

Nick
[hidden email]

Selameab, Tehout

It worked, finally! It worked on my desktop (but wouldn't work on my
laptop). No idea why! Just happy it worked and I can move on with my
work!


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