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: reshape or something else?


From   Nick Bornschein <[email protected]>
To   [email protected]
Subject   Re: st: reshape or something else?
Date   Thu, 28 Nov 2013 13:58:24 +0100

Sorry, one last question:

it it possible that all values of a specific level share the same row? With your syntax I get:

clear
input level q1 q2 q3
2 2.05 . .
2 . 3.01 .
2 . . 0.75
3 1.99 . .
3 . 1.86 .
3 . . 0.44
4 1.21 . .
4 . 4.22 .
4 . . 2.55
end

but I would need:

clear
input level q1 q2 q3
2 2.05 3.01 0.75
3 1.99 1.86 0.44
4 1.21 4.22 2.55
end




Am 28.11.13 13:21, schrieb Nick Cox:
clear
input value level str3 question
2.05 2 q1
3.01 2 q1
0.75 2 q1
1.99 3 q2
1.86 3 q2
0.44 3 q2
1.21 4 q3
4.22 4 q3
2.55 4 q3
end
gen id = _n
reshape wide value,  i(id level) j(question) string
drop id
renpfix value

Nick
[email protected]


On 28 November 2013 12:15, Nick Bornschein <[email protected]> wrote:
Not exactly: the final result should look like:

clear
input level q1 q2 q3
2 2.05 . .
2 3.01 . .
2 0.75 . .
3 . 1.99 .
3 . 1.86 .
3 . 0.44 .
4 . . 1.21
4 . . 4.22
4 . . 2.55
end



Am 28.11.13 12:55, schrieb Nick Cox:

Is this what you want? If not, show us explicitly what the reshaped
data should look like.

clear
input value level str3 question
2.05 2 q1
3.01 2 q1
0.75 2 q1
1.99 3 q2
1.86 3 q2
0.44 3 q2
1.21 4 q3
4.22 4 q3
2.55 4 q3
end
egen id = seq(), to(3)
reshape wide value level,  i(id) j(question) string


Nick
[email protected]


On 28 November 2013 11:39, Nick Bornschein <[email protected]>
wrote:

Yes, of course:

clear
input value level str3 question
2.05 2 q1
3.01 2 q1
0.75 2 q1
1.99 3 q2
1.86 3 q2
0.44 3 q2
1.21 4 q3
4.22 4 q3
2.55 4 q3
end

So the questions should be transferred to new variable q1, q2 and so on,
keeping the value and level information tne these two variables.

-Nick



Am 28.11.13 12:11, schrieb Nick Cox:

Please show us an example of your data, e.g. the first 10 observations.
Nick
[email protected]


On 28 November 2013 09:57, Nick Bornschein <[email protected]>
wrote:


Hello Stata user,

I have a dataset with 3 variables: "value" with numeric numbers,
"level"
with numeric levels from 1 to 10 and "question" with the short text of
the
questions (q1, q2...). Now I want to bring all the questions in
seperate
columns with the "value" they have in the variable "value"
coressponding
to
the level. Using reshape I always get error messages in some way, so
hope
there is an easy answer.

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


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

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

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

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

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


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