Try the below:
* HHID is just the first 12 characters of CASEID, so you can use the following to construct HHID in the KR file:
gen hwhhid = substr(caseid,1,12)
* The line number variable to use is then b16 (line number from the household schedule).
* Note that b16 is 0 if the child does not live in the household, but was a visitor.
gen hwline = b16
* You can then merge using the following command. This uses a many to 1 merge because of the cases above that can have 0 on b16.
merge m:1 hwhhid hwline using "bdhw4jfl.dta"
* Drop the extra cases from the 'using' file that we don't want.
drop if _merge==2