The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Dataset use in Stata » Reshaping data using Stata
Reshaping data using Stata [message #3397] Fri, 05 December 2014 02:22 Go to next message
Mercysh is currently offline  Mercysh
Messages: 35
Registered: April 2014
Member
I would appreciate some help regarding reshaping of the variables b16_01 to b16_20 (from individual datasets)so that I have one variable that I can compare with hv112 (from PR file),for mothers reported to be on the household schedule and whose children are younger than 18 years. I have followed a few examples but not getting it right.

Mercy
Re: Reshaping data using Stata [message #3484 is a reply to message #3397] Tue, 16 December 2014 10:04 Go to previous messageGo to next message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 3017
Registered: February 2013
Senior Member
Your post is being reviewed by a DHS moderator, and someone will respond soonest.

Thanks for your patience.
Re: Reshaping data using Stata [message #3486 is a reply to message #3397] Tue, 16 December 2014 12:40 Go to previous messageGo to next message
Trevor-DHS is currently offline  Trevor-DHS
Messages: 787
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==.
Re: Reshaping data using Stata [message #26149 is a reply to message #3486] Sat, 11 February 2023 06:44 Go to previous messageGo to next message
vkyni is currently offline  vkyni
Messages: 4
Registered: February 2023
Member
I'm working on IR file, I want to use only the b5_ variable, and in India DHS, it ranges from b5_01 to b5_20.
So my query is how to reshape it.
I'm trying to do it with the codes given as

reshape long b5_ , i(caseid) j(bindex)

But it is not giving the correct results when I'm checking it with couple file(where b5 is directly given), I tried this code also

reshape long b5_0 , i(caseid) j(bindex)

but here, the j goes from 0 to 9 only.

Please help me with this.
Re: Reshaping data using Stata [message #26151 is a reply to message #26149] Sat, 11 February 2023 07:23 Go to previous message
vkyni is currently offline  vkyni
Messages: 4
Registered: February 2023
Member
Sorry for the concern. There was some issue with my system; the code is working.
Thank you

[Updated on: Sat, 11 February 2023 07:24]

Report message to a moderator

Previous Topic: Antenatal care at least four in India nfhs report matching
Next Topic: Antenatal care from medically trained provider
Goto Forum:
  


Current Time: Thu Mar 28 15:37:54 Coordinated Universal Time 2024