Statalist


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

st: AW: Reshape


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: Reshape
Date   Thu, 16 Apr 2009 15:31:16 +0200

<> 



*************

clear*

inp caseid v001 v002
130456  34  1
123423  21  1
231465  43  1
345677  65  0
end

lab def yesno 1 "yes" 0 "no"
la val v002 yesno


local newvars "midx_01 midx_02 midx_03 midx_04 midx_05 midx_06 midx_07
midx_08 midx_09 vx_01 vx_02 vx_03 vx_04 vx_05 vx_06 vx_07 vx_08 vx_09"


foreach var of local newvars{
		gen `var'=cond(runiform()<0.3,0,cond(runiform()<0.9,1,2))
}


reshape long midx_0 vx_0, i(caseid)

rename midx_0 midx
rename vx_0 vx
drop _j
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Solorzano
Mosquera, Jenniffer
Gesendet: Donnerstag, 16. April 2009 14:41
An: [email protected]
Betreff: st: Reshape

Hi everybody
How can I reshape this database?

Caseid v001 v002 midx_01 midx_02 midx_03 midx_04 midx_05 midx_06 midx_07
midx_08 midx_09 vx_01 vx_02 vx_03 vx_04 vx_05 vx_06 vx_07 vx_08 vx_09 

130456  34   yes    1	   0       0       .       .       .      .
.       .       2     1     1     .      .     .     .      .      .
123423  21   yes    1      1       1       0       .       .      .
.       .       
231465  54   yes 
345677  65   no

I want

Caseid     v001    v002      midx   vx

130456	34      yes       1      2
130456	34	  yes       0      1
130456	34	  yes       0      1
130456	34	  yes       .      .
130456	34	  yes       .      .
130456	34	  yes       .
130456	34	  yes       .
130456	34	  yes       .
130456	34	  yes       .
123423	21	  yes       1
123423	21      yes       1
123423	21      yes       1      
123423	21	  yes       0
123423	21      yes		.
123423	21      yes       .
123423	21
123423	21
123423      21
.
.
.
345677      65      no
345677      65      no


Each caseid has one to 20 cases, but I'm trying to use the whole
information for the total of the 20 cases instead each caseid. Trying to
calculate child mortality rate by direct method..

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



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