Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Re: (no subject)


From   Jhilbe@aol.com
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Re: (no subject)
Date   Thu, 14 Apr 2005 13:26:37 EDT

I guess that Joe has in mind here his -unblock-  program published in STB-7. 
I can't find a record of any sibling -block-.  

As earlier posted, combining -reshape- and -expand-  gives an  official Stata 
solution. 

Nick 
n.j.cox@durham.ac.uk  
=====================================

Nick:

Well, you may be  correct. However, but it seems that I also wrote programs 
called -fold- and  -unfold- as well. Those were the ones I remembered
when reading the email.  Here is the -unfold- ado file, and its associated
help file. I notice now  that it is written in version 3.0 code.  Presumably 
it 
should work, but  it may need updating. The logic remains the same so that 
anyone wanting to  amend it to current version code may do so. Of course, 
one may simply use a  combo of Stata's expand command. But I found using 
this program (or  block/unblock - they were published together) much easier. 
I 
have to admit  that the program appears rather primitive -- it's 13 years old 
now. 

Joe  Hilbe

*! version 3.0.0  4/23/92 Hilbe
capture program drop  unfold
program define unfold
version 3.0 
local varlist  "req ex min(2)"
parse "`*'"
parse "`varlist'", parse("  ")
confirm new var _`1'
confirm new var _`2'
local k  = _N
local k1 = _N + 1
quietly expand =2,  clear

capture {
gen byte _`1'=0 in 1/`k'
replace _`1'=1 in `k1'/l
gen _`2'=`2'-`1' in 1/`k'
replace  _`2'=`1' in `k1'/l
mac shift
mac  shift

}
noisily di in bl " Blocked data  unfolded..."
local rc = _rc
error `rc'  

end

=========================================

================================================

Help  of ^unfold^ : Program to unfold or unblock data  sets
--------------------------------------------------------
Joseph  Hilbe, Editor STB

The syntax for ^unfold^  is:

^unfold^  pos_var pop_var [rhsvar]

pos_var is a variable containing  the number of positive responses for a 
group or block. pop_var is the total  cases in a block or group. 
Right-hand-side covariates will be appropriately  handled; you do not 
need to name them on the command line.   

Consider the following grouped data  set:

infec     cases      cd4     cd8
1.        2          2         1       2
2.        4          7         0       0
3.        1          3         2       2
4.        0          2         2       0

The first observation tells us  that there are two cases having the values of 
1 and 2 for cd4 and cd8  respectively. Moreover, both of these  
cases have a positive response  (i.e. infection occurs). The second 
observation represents a group  consisting of four positive responses 
out of seven cases for a covariate  pattern of 0 0.

^unfold^ literally unfolds or ungroups a data set. In  order to do this 
two new variables are created.


^. unfold infec  cases
Blocked data set  unfolded...

^.l

infec     cases      cd4     cd8      _infec     _cases
1.       2          2         1        2           0           0
2.       4          7         0        0           0           3
3.       1          3         2        2           0          2  
4.       0          2         2        0           0           2
5.       2          2         1        2           1           2
6.       4          7         0        0           1           4
7.       1          3         2        2           1           1
8.       0          2         2        0           1          0


Notice that  the first observation, having a covariate pattern of 1 2, shows 
no cases  with a non-positive outcome. Observation 5, having the same pattern,
records  two positive responses (infections). This accords with what we saw 
in the  grouped format. Also notice that the newly created variables of 
interest  have the same name as the original grouped variables, except that 
they have  a leading underscore. Although the original variable could have 
been  discarded in the transformation, I decided to retain them in the 
ungrouped  data set in case a user may find them valuable. However, they are 
not needed  for most subsequent analysis.

Remember, when performing subsequent  analysis, ^_cases^ is a frequency 
weight. Hence, a logistic regression of  the above data set would look  like:

^logistic^ _infec cd4 cd8 [fw=_cases]

Of course, you may rename the  underscored variables to anything you
like. Refer to ^sqv4^ for use with  blocked logistic  regression.

========================================================================

Joe  Hilbe

> I once wrote an ado file for the  STB called -unfold-,  which  went 
together 
> with -fold-. It is in -sqv4 in one of   the old STB's. It should be easy to 
find 
> looking at the early STBs on  Stata's  web site. The -unfold-  program was 
> designed for  this exact situation. The help  file that goes with the 
program 
>  advises how to use it appropriately. If you have  difficulties locating 
it,  let me 
> know privately and I'll send it to you.  
> 
>  I also recall that there are now other Stata programs in existence that   
can 
> do the same thing, but cannot think of their names.  

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index