The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Dataset use in Stata » Reshaping data using Stata
Re: Reshaping data using Stata [message #3486 is a reply to message #3397] Tue, 16 December 2014 12:40 Go to previous messageGo to previous message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 794
Registered: January 2013
Senior Member
I would suggest starting with the Births Recode (BR) dataset, rather than the IR dataset, as that file is already reshaped.

If you want to reshape the file you can use something like:
use "NGIR6AFL.DTA"
* keep the variables of interest, e.g.
* If you don't limit the number of variables, the reshape is really, really slow.
keep caseid v000 v005 v008 v013 v201 b*
* Rename all of the repeating variables to drop the leading 0 to help with reshaping
rename b*_0* b*_*
* Reshape the file into a sibling history file
* This will be slow to run and could take 5 minutes or more.
reshape long bidx_ bord_ b0_ b1_ b2_ b3_ b4_ b5_ b6_ b7_ b8_ b9_ b10_ b11_ b12_ b13_ b15_ b16_, i(caseid) j(bindex)
* Rename to drop the trailing underscore on the end of the reshaped variables
rename b*_ b*
* Drop empty entries
drop if bidx==.
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Antenatal care at least four in India nfhs report matching
Next Topic: Antenatal care from medically trained provider
Goto Forum:
  


Current Time: Sun May 12 00:13:15 Coordinated Universal Time 2024