I have two datasets. One dataset has an individual identifier , and some of the variables in that dataset points to an identifier in another dataset. I want to get the entries from the second dataset as variables in the first dataset. These are the data examples
DATASET 1:
DATASET 2:
so the fs203_coreside_child* variables in the first dataset gives me the last digits of the prim_key of the second dataset. I want the cv007 variable values as separate variables for the different prim_keys that the coreside variables give me. Eg 101000100130101 has a fs203_coreside_child5 value of 6 in first dataset, means that in the second dataset, 101000100130106 is my target observation, and I want the cv007 value of that observation as a variable (say cv007_child5) which takes that value . Similarly, the same 101000100130101 prim_key has fs203_coreside_child6 value of 7 in first dataset, so 101000100130107 in the second dataset is the target observation, and the cv007 value from there goes to another variable (saycv007_child6). This needs to be done for all prim_keys for the first dataset.
I guess there is a reshape problem here, but I am clueless as to how to approach this problem. Any help would be appreciated.
DATASET 1:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str15(prim_key hhid) byte stateid int ssuid byte(fs203_coreside_child1 fs203_coreside_child2 fs203_coreside_child3 fs203_coreside_child4 fs203_coreside_child5 fs203_coreside_child6) "101000100040101" "101000100040100" 1 1 .e .e .e . . . "101000100040102" "101000100040100" 1 1 .e .e .e . . . "101000100130101" "101000100130100" 1 1 3 .e .e .e 6 7 "101000100130102" "101000100130100" 1 1 3 .e .e .e 6 7 "101000100130109" "101000100130100" 1 1 .e . . . . . "101000100250106" "101000100250100" 1 1 .e .e .e .e 1 . "101000100320101" "101000100320100" 1 1 .e 3 6 7 8 . "101000100320102" "101000100320100" 1 1 .e 3 6 7 8 . "101000100320109" "101000100320100" 1 1 1 .e .e .e . . "101000100370102" "101000100370100" 1 1 3 4 5 . . . "101000100370111" "101000100370100" 1 1 .e 1 .e 6 . . "101000100590101" "101000100590100" 1 1 .e .e 3 .e 4 8 "101000100590102" "101000100590100" 1 1 .e .e 3 .e 4 8 "101000100760101" "101000100760100" 1 1 4 5 6 . . . "101000100760102" "101000100760100" 1 1 .e 3 .e 4 5 6 "101000101040101" "101000101040100" 1 1 .e .e .e .e 3 .e "101000101040102" "101000101040100" 1 1 .e .e .e .e 3 .e "101000101330101" "101000101330100" 1 1 . . . . . . "101000101720101" "101000101720100" 1 1 .e 2 .e 5 6 7 "101000101890107" "101000101890100" 1 1 .e .e 1 6 .e . "101000102490101" "101000102490100" 1 1 .e .e 3 .e . . "101000102490102" "101000102490100" 1 1 .e .e 3 .e . . "101000103350101" "101000103350100" 1 1 .e 3 4 5 6 7 "101000103350102" "101000103350100" 1 1 .e 3 4 5 6 7 "101000103550101" "101000103550100" 1 1 2 .e . . . . "101000103550102" "101000103550100" 1 1 3 5 6 7 8 . "101000103690101" "101000103690100" 1 1 .e 3 .e .e . . "101000103690102" "101000103690100" 1 1 .e 3 .e .e . . "101000104030101" "101000104030100" 1 1 . . . . . . "101000104030102" "101000104030100" 1 1 3 .e 4 5 6 . "101000104240101" "101000104240100" 1 1 3 .e .e 8 . . "101000104240102" "101000104240100" 1 1 3 .e .e 8 . . "101000200050101" "101000200050100" 1 2 .e .e .e 3 .e .e "101000200050102" "101000200050100" 1 2 .e .e .e 3 .e .e "101000200160109" "101000200160100" 1 2 2 . . . . . "101000200210101" "101000200210100" 1 2 .e .e .e 3 .e 4 "101000200210102" "101000200210100" 1 2 .e .e .e 3 .e 4 "101000200210108" "101000200210100" 1 2 .e .e 1 .e .e .e "101000200270101" "101000200270100" 1 2 2 3 4 5 6 . "101000200290108" "101000200290100" 1 2 .e .e .e 1 .e .e "101000200290109" "101000200290100" 1 2 . . . . . . "101000200340101" "101000200340100" 1 2 3 4 . . . . "101000200340102" "101000200340100" 1 2 3 4 . . . . "101000200470101" "101000200470100" 1 2 .e .e .e .e 3 .e "101000200470102" "101000200470100" 1 2 .e .e .e .e .e 3 "101000200740101" "101000200740100" 1 2 2 . . . . . "101000200860102" "101000200860100" 1 2 3 4 5 6 7 8 "101000201190106" "101000201190100" 1 2 .e .e .e .e .e .e "101000201360101" "101000201360100" 1 2 .e .e .e .e .e 3 "101000201360102" "101000201360100" 1 2 .e .e .e .e .e 3 "101000201360103" "101000201360100" 1 2 . . . . . . "101000201560108" "101000201560100" 1 2 .e .e .e .e .e 1 "101000201670110" "101000201670100" 1 2 . . . . . . "101000202130102" "101000202130100" 1 2 .e .e 3 4 5 6 "101000202440101" "101000202440100" 1 2 .e .e .e 3 . . "101000202440102" "101000202440100" 1 2 .e .e .e 3 . . "101000203010101" "101000203010100" 1 2 .e .e 3 .e 5 .e "101000203010102" "101000203010100" 1 2 .e .e 3 .e 5 .e "101000203460101" "101000203460100" 1 2 .e .e 3 4 5 . "101000203460102" "101000203460100" 1 2 . . . . . . "101000300030201" "101000300030200" 1 3 .e .e .e 4 5 . "101000300030202" "101000300030200" 1 3 .e 3 .e 4 5 . "101000300070105" "101000300070100" 1 3 .e .e 2 .e . . "101000300140106" "101000300140100" 1 3 .e .e 1 .e .e .e "101000300220101" "101000300220100" 1 3 6 2 .e 3 4 5 "101000300260101" "101000300260100" 1 3 3 4 5 6 7 8 "101000300260102" "101000300260100" 1 3 3 4 5 6 7 8 "101000300380205" "101000300380200" 1 3 .e .e .e .e .e 1 "101000300550105" "101000300550100" 1 3 .e .e .e . . . "101000300920101" "101000300920100" 1 3 .e 3 4 5 . . "101000300920102" "101000300920100" 1 3 .e 3 4 5 . . "101000301080101" "101000301080100" 1 3 .e 3 . . . . "101000301080102" "101000301080100" 1 3 .e 3 . . . . "101000301450201" "101000301450200" 1 3 .e .e .e .e 3 . "101000301450202" "101000301450200" 1 3 .e .e .e .e 3 . "101000301720106" "101000301720100" 1 3 .e .e .e 1 . . "101000301840101" "101000301840100" 1 3 .e .e 3 4 .e . "101000301840102" "101000301840100" 1 3 .e .e .e .e .e . "101000302140101" "101000302140100" 1 3 .e 3 4 . . . "101000302140102" "101000302140100" 1 3 .e 3 4 . . . "101000302250106" "101000302250100" 1 3 . . . . . . "101000302720104" "101000302720100" 1 3 .e 1 .e .e . . "101000303240201" "101000303240200" 1 3 .e .e 2 3 . . "101000400040101" "101000400040100" 1 4 .e .e 3 .e . . "101000400040102" "101000400040100" 1 4 .e .e 3 .e . . "101000400070107" "101000400070100" 1 4 .e .e .e 1 .e .e "101000400070108" "101000400070100" 1 4 .e .e .e .e .e .e "101000400120101" "101000400120100" 1 4 .e 3 6 7 8 . "101000400120102" "101000400120100" 1 4 .e 3 6 7 8 . "101000400120109" "101000400120100" 1 4 1 .e . . . . "101000400140101" "101000400140100" 1 4 3 .e .e 5 6 .e "101000400140102" "101000400140100" 1 4 3 .e .e 5 6 .e "101000400230102" "101000400230100" 1 4 3 .e 8 9 10 . "101000400230111" "101000400230100" 1 4 1 .e .e .e .e .e "101000400430201" "101000400430200" 1 4 .e .e .e .e 3 5 "101000400430202" "101000400430200" 1 4 .e .e .e .e 3 5 "101000400610101" "101000400610100" 1 4 3 9 .e 11 . . "101000400610102" "101000400610100" 1 4 3 .e 9 11 . . "101000400930101" "101000400930100" 1 4 .e 3 4 5 6 7 "101000400930102" "101000400930100" 1 4 .e 3 4 5 6 7 end label values stateid stateid_cv label def stateid_cv 1 "1 Jammu and Kashmir", modify label values fs203_coreside_child1 _vl8884_ind label values fs203_coreside_child2 _vl8885_ind label values fs203_coreside_child3 _vl8886_ind label values fs203_coreside_child4 _vl8887_ind label values fs203_coreside_child5 _vl8888_ind label values fs203_coreside_child6 _vl8889_ind
DATASET 2:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str15(prim_key hhid) byte(cv007 cv008 cv009 cv010) "101000100040201" "101000100040200" 3 1 8 3 "101000100040202" "101000100040200" 3 1 9 3 "101000100040203" "101000100040200" 4 1 0 . "101000100040204" "101000100040200" . . . . "101000100040205" "101000100040200" . . . . "101000100130103" "101000100130100" 3 1 15 7 "101000100130104" "101000100130100" 3 1 12 5 "101000100130105" "101000100130100" . . . . "101000100130106" "101000100130100" 3 1 12 5 "101000100130107" "101000100130100" 3 1 12 5 "101000100130108" "101000100130100" 3 1 9 3 "101000100250101" "101000100250100" 3 1 10 4 "101000100250102" "101000100250100" 3 1 15 7 "101000100250103" "101000100250100" 4 1 0 . "101000100250104" "101000100250100" . . . . "101000100250105" "101000100250100" . . . . "101000100320103" "101000100320100" 3 1 12 5 "101000100320104" "101000100320100" 3 1 9 3 "101000100320105" "101000100320100" . . . . "101000100320106" "101000100320100" 3 1 11 4 "101000100320107" "101000100320100" 3 1 10 4 "101000100320108" "101000100320100" 3 1 12 4 "101000100370101" "101000100370100" 3 1 1 5 "101000100370103" "101000100370100" 3 1 17 8 "101000100370104" "101000100370100" 3 1 16 5 "101000100370105" "101000100370100" 3 1 11 4 "101000100370106" "101000100370100" 3 1 15 7 "101000100370107" "101000100370100" 3 1 15 5 "101000100370108" "101000100370100" 4 1 1 1 "101000100370109" "101000100370100" . . . . "101000100370110" "101000100370100" . . . . "101000100590103" "101000100590100" 4 2 . . "101000100590104" "101000100590100" 3 1 8 3 "101000100590105" "101000100590100" 3 1 6 2 "101000100590106" "101000100590100" . . . . "101000100590107" "101000100590100" . . . . "101000100590108" "101000100590100" 4 2 . . "101000100760103" "101000100760100" 3 1 9 3 "101000100760104" "101000100760100" 3 1 9 3 "101000100760105" "101000100760100" 3 1 4 1 "101000100760106" "101000100760100" 3 1 6 2 "101000100760107" "101000100760100" 4 2 . . "101000101040103" "101000101040100" 3 1 10 4 "101000101040104" "101000101040100" 3 1 10 3 "101000101040105" "101000101040100" 3 1 8 3 "101000101040106" "101000101040100" 3 1 7 2 "101000101040107" "101000101040100" 3 1 4 2 "101000101040108" "101000101040100" 3 1 2 1 "101000101040109" "101000101040100" . . . . "101000101040110" "101000101040100" . . . . "101000101190201" "101000101190200" 3 1 9 3 "101000101190202" "101000101190200" 3 1 12 5 "101000101190203" "101000101190200" . . . . "101000101190204" "101000101190200" . . . . "101000101330102" "101000101330100" 4 2 . . "101000101330103" "101000101330100" 3 1 9 3 "101000101330104" "101000101330100" 3 1 4 1 "101000101330105" "101000101330100" 1 1 1 1 "101000101330106" "101000101330100" . . . . "101000101490101" "101000101490100" 3 1 10 4 "101000101490102" "101000101490100" 3 1 8 3 "101000101490103" "101000101490100" 3 1 6 2 "101000101490104" "101000101490100" 3 1 4 1 "101000101490105" "101000101490100" 3 1 4 1 "101000101720102" "101000101720100" 3 1 10 4 "101000101720103" "101000101720100" 3 1 10 4 "101000101720104" "101000101720100" . . . . "101000101720105" "101000101720100" 3 1 8 3 "101000101720106" "101000101720100" 3 1 8 3 "101000101720107" "101000101720100" 3 1 9 3 "101000101720108" "101000101720100" 3 1 8 3 "101000101890101" "101000101890100" 3 1 17 9 "101000101890102" "101000101890100" 3 1 13 5 "101000101890103" "101000101890100" 3 1 2 1 "101000101890104" "101000101890100" 4 1 0 . "101000101890105" "101000101890100" . . . . "101000101890106" "101000101890100" 4 2 . . "101000102090101" "101000102090100" 3 1 10 4 "101000102090102" "101000102090100" 3 1 10 4 "101000102090103" "101000102090100" 4 1 2 1 "101000102090104" "101000102090100" 4 1 1 1 "101000102090105" "101000102090100" . . . . "101000102210101" "101000102210100" 3 1 9 3 "101000102210102" "101000102210100" 3 1 9 3 "101000102210103" "101000102210100" . . . . "101000102210104" "101000102210100" . . . . "101000102210105" "101000102210100" . . . . "101000102490103" "101000102490100" 3 1 11 4 "101000102660101" "101000102660100" 3 1 10 3 "101000102660102" "101000102660100" 3 1 10 3 "101000102660103" "101000102660100" 4 1 1 1 "101000102660104" "101000102660100" . . . . "101000102660105" "101000102660100" . . . . "101000102870201" "101000102870200" 3 1 15 8 "101000102870202" "101000102870200" 3 1 12 5 "101000102870203" "101000102870200" 4 1 1 1 "101000102870204" "101000102870200" . . . . "101000102870205" "101000102870200" . . . . "101000102970201" "101000102970200" 3 1 9 3 "101000102970202" "101000102970200" 3 1 10 4 end label values cv007 lasi_vl216_cv label def lasi_vl216_cv 1 "1 Can read only", modify label def lasi_vl216_cv 3 "3 Can both read and write", modify label def lasi_vl216_cv 4 "4 Cannot read or write", modify label values cv008 lasi_vl251_cv label def lasi_vl251_cv 1 "1 Yes", modify label def lasi_vl251_cv 2 "2 No", modify label values cv010 lasi_vl321_cv label def lasi_vl321_cv 1 "1 Less than Primary school (Standard 1-4)", modify label def lasi_vl321_cv 2 "2 Primary school completed (Standard 5-7)", modify label def lasi_vl321_cv 3 "3 Middle school completed (Standard 8- 9)", modify label def lasi_vl321_cv 4 "4 Secondary school/Matriculation completed", modify label def lasi_vl321_cv 5 "5 Higher secondary/intermediate/senior secondary completed", modify label def lasi_vl321_cv 7 "7 Graduate degree (B.A., B.Sc., B. Com.) completed", modify label def lasi_vl321_cv 8 "8 Post-graduate degree or (M.A., M.Sc., M. Com.) above (M.Phil, Ph.D., Post-Doc) completed", modify label def lasi_vl321_cv 9 "9 Professional course/degree (B.Ed, BE, B.Tech, MBBS, BHMS, BAMS, B.Pharm, BCS, BCA, BBA, LLB) (BVSc., B. Arch, M.Ed, ME, M.Tech, MD, M.Pharm, MCS, MCA, MBA,LLM, MVSc., M. Arch, MS, CA, CS, CWA) completed", modify
so the fs203_coreside_child* variables in the first dataset gives me the last digits of the prim_key of the second dataset. I want the cv007 variable values as separate variables for the different prim_keys that the coreside variables give me. Eg 101000100130101 has a fs203_coreside_child5 value of 6 in first dataset, means that in the second dataset, 101000100130106 is my target observation, and I want the cv007 value of that observation as a variable (say cv007_child5) which takes that value . Similarly, the same 101000100130101 prim_key has fs203_coreside_child6 value of 7 in first dataset, so 101000100130107 in the second dataset is the target observation, and the cv007 value from there goes to another variable (saycv007_child6). This needs to be done for all prim_keys for the first dataset.
I guess there is a reshape problem here, but I am clueless as to how to approach this problem. Any help would be appreciated.
Comment