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: RE: stack related (simple) problem


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: RE: stack related (simple) problem
Date   Thu, 3 Mar 2011 21:22:48 +0000

OK. -duplicates- is a pertinent command. 

Nick 
[email protected] 


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Enayetur Raheem
Sent: 03 March 2011 21:12
To: [email protected]
Subject: st: RE: stack related (simple) problem

Sorry for my ambiguous statement. There is no problem in applying the
-reshape- command and getting the result. What I wanted to achieve is to
get the output as:

11
12
13
21
22
23
31
32
33
-- a vector of length 9; not as a vector of length 27, which -reshape-
will otherwise produce when applied to 

11 12 13
11 12 13
11 12 13
21 22 23
21 22 23
21 22 23
31 32 33
31 32 33
31 32 33

What I meant in my previous post--is to remove the duplicate rows, and
then apply -reshape- to get desired result. Hope, I've cleared the
ambiguity now :)

And as always, thanks for your help.


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: March-03-11 3:57 PM
To: '[email protected]'
Subject: st: RE: RE: RE: stack related (simple) problem

I can't see that there should be _any_ problem to fix. Try 

clear
input v1 v2 v3
11 12 13
11 12 13
11 12 13
21 22 23
21 22 23
21 22 23
31 32 33
31 32 33
31 32 33
end
gen id = _n
reshape long v, i(id)

If you are not getting sensible results from your real data, you need to
tell us more, including more about your real data and your code. 

Nick
[email protected] 

Enayetur Raheem

Thanks a lot, Nick. The duplicates do not show up in the transformed
data, and that is why I was having trouble reshaping it (as I was not
getting the desired results). 

I guess, I will use some sort of loops to delete the duplicate rows from
the first example, and then apply -reshape-.

Nick Cox

Note that we can't comment on what you didn't understand if you don't
show us any code. 

I wouldn't -stack- this. 

I would -reshape-. 

The main reason is that -reshape- is very useful, but you need to
practise so that you can get used to it. I assume an identifier -id-. If
one does not exist, create it. 

gen id = _n 

reshape long v, i(id) 

You can -stack- too. 

stack v1 v2 v3, into(v4) clear 

I don't understand why the duplicates in your first example don't show
up in your second. I assume that's meaningless unless you explain to the
contrary. 

Nick
[email protected] 

Enayetur Raheem
 
I was trying to transform the following data 
 
v1 v2 v3
11 12 13
11 12 13
11 12 13
21 22 23
21 22 23
21 22 23
31 32 33
31 32 33
31 32 33
 
into a single variable, such as 
 
v4
11
12
13
21
22
23
31
32
33

I tried the -stack - command, but could not get it done. I am very new
to Stata, so I am not aware of many commands. Any suggestion will be
much appreciated. 

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