Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: WG: small problem with 'stack' command


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: WG: small problem with 'stack' command
Date   Fri, 25 Sep 2009 17:38:03 +0100

I share Martin's puzzlement here. 

First, there is no sense in which Marwan can have different numbers of observations for different variables. Perhaps, as Martin guesses, different numbers of non-missing values are meant, but that should make no difference to -stack-. 

Second, I have to guess that there is something very odd not revealed here, perhaps that Marwan's code is doing more than he says, or that his Stata is corrupted. Either way, this should be taken forwarded with Stata tech-support, unless Marwan can tell us more. 

Nick 
[email protected] 

Martin Weiss

I cannot see what your problem really is. In my example, everything
seems to work just fine.

*************
clear*
set obs 50
 
gen gp5=rnormal()
gen gp4=rnormal() in 1/48
gen gp3=rnormal() in 1/22
gen gp2=rnormal() in 1/36 
gen gp1=rnormal() in 1/48 

stack gp*, into(overall) /* 
*/ wide clear

list, noobs

//get summary of "overall"
summ overall, det
*************

Marwan Elkhoury

to clarify my previous post, I have 5 groups of countries, each one
containing a different number of observations, say group 1 has 48
observations, gp2 has 36 obs, gp3 has 22 obs, gp4 has 48 and gp5 has 50, so,
in total, I have 204 observations; for each group of countries, I have
estimated a score and a ranking.  Now, I need to stack up all these
countries together to get an overall score and estimate the overall ranking.

When I try to stack all the variables together, the 'stack' command cuts
each group to 22 observations, (least common number of observations in each
group), dropping the rest of observations.  thus, I end up with a group
having 5x22= 110 observations instead of 204 observations. that's the
problem.  Any idea how to adjust it ?

Copy of previous post:
dear statalist,

I have a minor problem with the 'stack' command in stata (stata 10 for  
windows xp).

I have 5 groups of countries of various size length which I want to  
stack into a single group of two variables, say, ctryg totrnk.

right now I have cntry_i, rnk_i, for i=1 to 5
and if I write the following:

stack cntry_1 rnk_1 cntry_2 rnk_2 cntry_3 rnk_3 cntry_4 rnk_4 cntry_5  
rnk_5, into(cntry_1 rnk_1) wide clear
ren cntry_1 cntryg
ren rnk_1 totrnk

It, in fact, creates two variables of size length the smallest of the  
size length of the groups and not stacking the entire number of  
observations.

what would be the easiest and smartest way of stacking this  
'unbalanced' group of variables, if any, to create one group of two  
variables from the 5 different groups ?


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index