The DHS Program User Forum
Discussions regarding The DHS Program data and results
Home » Data » Merging data files » Generating ID variable
Generating ID variable [message #14878] Thu, 10 May 2018 19:49 Go to next message
sumonrupop is currently offline  sumonrupop
Messages: 20
Registered: August 2015
Location: Rajshahi
Member

Dear All,
I am trying to make a new cluster number based on the cluster number available in the data set for merging with geographical data, but so far without any luck. The new id that I'd like to make should be 8 digits where 2 are string and others are numeric, where 3 digit available in the data set. As for example, i need to replace cluster number 001 with BD2014001.

Any help would be appreciate.


Md. Nuruzzaman Khan
Re: Generating ID variable [message #14882 is a reply to message #14878] Fri, 11 May 2018 09:06 Go to previous messageGo to next message
Bridgette-DHS is currently offline  Bridgette-DHS
Messages: 1495
Registered: February 2013
Senior Member

Following is a response from Senior DHS Stata Specialist, Tom Pullum:

The only complication with this is that you need to insert leading zeroes when the cluster code is less than 100. The following lines will do this within the PR file.

gen str3 strhv001=string(hv001)
replace strhv001="0"+string(hv001) if hv001<100
replace strhv001="00"+string(hv001) if hv001<10
replace strhv001="BD2014"+strhv001

The constructed variable will automatically reset to 9 columns, even though it started with 3.

Re: Generating ID variable [message #14883 is a reply to message #14882] Fri, 11 May 2018 10:00 Go to previous message
sumonrupop is currently offline  sumonrupop
Messages: 20
Registered: August 2015
Location: Rajshahi
Member

many thanks

Md. Nuruzzaman Khan
Previous Topic: MERGING THREE DHS DATASETS
Next Topic: Merging IR and KR with PR - no unique identifiers (for particular countries only)
Goto Forum:
  


Current Time: Thu Nov 15 12:39:25 Eastern Standard Time 2018