Hi everyone,
I am trying to change my data into a wide format such that I can have 9 separate variables one for each food item and in front of each food item I'd like to have the number of days that food item was consumed in the last 7 days (in the data this variable is called q91a". The problem is that for each household, the order of the food item is different. So the reshape command
works but then in each column, I get all food items whereas I need one column per food item and the number of days that food item was consumed next to it. If a household only has 3 food items, then that automatically means it didn't consume the other 6 items and I'd like to have a zero in the variable "q91a" for such instances. Will appreciate any help on this.
I am trying to change my data into a wide format such that I can have 9 separate variables one for each food item and in front of each food item I'd like to have the number of days that food item was consumed in the last 7 days (in the data this variable is called q91a". The problem is that for each household, the order of the food item is different. So the reshape command
Code:
reshape wide q91a fitem2, i(parent_key) j(fitem)
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str41 parent_key float fitem long q91 byte(q91a dup) "uuid:0006cab2-ef5d-4dd1-a28b-ead8ee7d7748" 1 9 7 3 "uuid:0006cab2-ef5d-4dd1-a28b-ead8ee7d7748" 2 1 7 3 "uuid:0006cab2-ef5d-4dd1-a28b-ead8ee7d7748" 3 8 7 3 "uuid:0006cab2-ef5d-4dd1-a28b-ead8ee7d7748" 4 4 4 3 "uuid:001be491-db68-4f5a-8069-4be05cad5495" 1 1 4 0 "uuid:0023c936-6c6a-48e3-af4a-9257ecfea068" 1 8 7 1 "uuid:0023c936-6c6a-48e3-af4a-9257ecfea068" 2 4 2 1 "uuid:003a60cc-1fee-4a1e-9d3d-747a0db19cb0" 1 6 7 7 "uuid:003a60cc-1fee-4a1e-9d3d-747a0db19cb0" 2 1 7 7 "uuid:003a60cc-1fee-4a1e-9d3d-747a0db19cb0" 3 8 1 7 "uuid:003a60cc-1fee-4a1e-9d3d-747a0db19cb0" 4 9 7 7 "uuid:003a60cc-1fee-4a1e-9d3d-747a0db19cb0" 5 4 7 7 "uuid:003a60cc-1fee-4a1e-9d3d-747a0db19cb0" 6 7 7 7 "uuid:003a60cc-1fee-4a1e-9d3d-747a0db19cb0" 7 5 7 7 "uuid:003a60cc-1fee-4a1e-9d3d-747a0db19cb0" 8 3 7 7 "uuid:005d9846-76bf-41e6-b48b-61849fe458b0" 1 8 7 0 "uuid:00879996-134a-4134-9a86-b270f0aca35f" 1 8 7 5 "uuid:00879996-134a-4134-9a86-b270f0aca35f" 2 7 2 5 "uuid:00879996-134a-4134-9a86-b270f0aca35f" 3 1 3 5 "uuid:00879996-134a-4134-9a86-b270f0aca35f" 4 3 2 5 "uuid:00879996-134a-4134-9a86-b270f0aca35f" 5 5 1 5 "uuid:00879996-134a-4134-9a86-b270f0aca35f" 6 4 2 5 "uuid:008f24b5-fda4-492e-b760-cae7b51d6f85" 1 3 4 1 "uuid:008f24b5-fda4-492e-b760-cae7b51d6f85" 2 4 4 1 "uuid:008f9b90-2bef-4772-bcf2-56c98c2bbe9c" 1 4 7 5 "uuid:008f9b90-2bef-4772-bcf2-56c98c2bbe9c" 2 3 7 5 "uuid:008f9b90-2bef-4772-bcf2-56c98c2bbe9c" 3 9 1 5 "uuid:008f9b90-2bef-4772-bcf2-56c98c2bbe9c" 4 1 7 5 "uuid:008f9b90-2bef-4772-bcf2-56c98c2bbe9c" 5 8 3 5 "uuid:008f9b90-2bef-4772-bcf2-56c98c2bbe9c" 6 7 3 5 "uuid:00a8a941-6b7a-4f83-89fe-18629789e083" 1 4 3 0 "uuid:00e3c79b-5a88-4df3-a17b-f66e9a27ebfe" 1 8 7 4 "uuid:00e3c79b-5a88-4df3-a17b-f66e9a27ebfe" 2 7 2 4 "uuid:00e3c79b-5a88-4df3-a17b-f66e9a27ebfe" 3 5 5 4 "uuid:00e3c79b-5a88-4df3-a17b-f66e9a27ebfe" 4 8 2 4 "uuid:00e3c79b-5a88-4df3-a17b-f66e9a27ebfe" 5 4 3 4 "uuid:00fd5e1c-3c91-477f-abf4-4c2252e461c0" 1 4 3 2 "uuid:00fd5e1c-3c91-477f-abf4-4c2252e461c0" 2 1 3 2 "uuid:00fd5e1c-3c91-477f-abf4-4c2252e461c0" 3 8 7 2 "uuid:00fec75e-07c6-422d-83b1-4683f16756ae" 1 7 7 4 "uuid:00fec75e-07c6-422d-83b1-4683f16756ae" 2 4 7 4 "uuid:00fec75e-07c6-422d-83b1-4683f16756ae" 3 5 1 4 "uuid:00fec75e-07c6-422d-83b1-4683f16756ae" 4 3 4 4 "uuid:00fec75e-07c6-422d-83b1-4683f16756ae" 5 1 7 4 "uuid:0111045a-5996-4e99-ba26-3d31b77962a4" 1 4 5 1 "uuid:0111045a-5996-4e99-ba26-3d31b77962a4" 2 8 6 1 "uuid:0113ad53-122c-4905-9fe9-4eb3f902b68c" 1 4 7 1 "uuid:0113ad53-122c-4905-9fe9-4eb3f902b68c" 2 1 7 1 "uuid:012917de-c728-483e-ab35-77d240e932f3" 1 1 7 5 "uuid:012917de-c728-483e-ab35-77d240e932f3" 2 6 2 5 "uuid:012917de-c728-483e-ab35-77d240e932f3" 3 3 7 5 "uuid:012917de-c728-483e-ab35-77d240e932f3" 4 7 5 5 "uuid:012917de-c728-483e-ab35-77d240e932f3" 5 8 3 5 "uuid:012917de-c728-483e-ab35-77d240e932f3" 6 4 2 5 "uuid:012c972e-97ff-4a52-a82f-27ebe894e175" 1 1 1 3 "uuid:012c972e-97ff-4a52-a82f-27ebe894e175" 2 3 1 3 "uuid:012c972e-97ff-4a52-a82f-27ebe894e175" 3 4 3 3 "uuid:012c972e-97ff-4a52-a82f-27ebe894e175" 4 8 5 3 "uuid:01317a87-1b50-4f36-b9f3-e1faa9f55361" 1 8 7 0 "uuid:01337d35-de56-4927-9dae-22f5a05da776" 1 8 7 2 "uuid:01337d35-de56-4927-9dae-22f5a05da776" 2 4 7 2 "uuid:01337d35-de56-4927-9dae-22f5a05da776" 3 5 1 2 "uuid:015aad6a-3116-46dd-b369-fd8e85021ec3" 1 1 7 3 "uuid:015aad6a-3116-46dd-b369-fd8e85021ec3" 2 4 3 3 "uuid:015aad6a-3116-46dd-b369-fd8e85021ec3" 3 7 3 3 "uuid:015aad6a-3116-46dd-b369-fd8e85021ec3" 4 8 7 3 "uuid:016d7733-c8e9-4068-a7c2-bc29912f94e1" 1 5 2 6 "uuid:016d7733-c8e9-4068-a7c2-bc29912f94e1" 2 3 4 6 "uuid:016d7733-c8e9-4068-a7c2-bc29912f94e1" 3 4 7 6 "uuid:016d7733-c8e9-4068-a7c2-bc29912f94e1" 4 6 4 6 "uuid:016d7733-c8e9-4068-a7c2-bc29912f94e1" 5 7 7 6 "uuid:016d7733-c8e9-4068-a7c2-bc29912f94e1" 6 1 7 6 "uuid:016d7733-c8e9-4068-a7c2-bc29912f94e1" 7 8 2 6 "uuid:019d7036-bdf2-44f8-bd38-5f4505c39ce8" 1 8 7 0 "uuid:01a67cd9-e308-46ac-ab3e-476898ae6ebc" 1 4 3 3 "uuid:01a67cd9-e308-46ac-ab3e-476898ae6ebc" 2 6 3 3 "uuid:01a67cd9-e308-46ac-ab3e-476898ae6ebc" 3 8 7 3 "uuid:01a67cd9-e308-46ac-ab3e-476898ae6ebc" 4 1 7 3 "uuid:01ab6faa-cefe-4274-86b3-bddaa49b7f9d" 1 4 7 2 "uuid:01ab6faa-cefe-4274-86b3-bddaa49b7f9d" 2 8 7 2 "uuid:01ab6faa-cefe-4274-86b3-bddaa49b7f9d" 3 7 5 2 "uuid:01ac43f1-4ddb-4ced-8a73-634b1a2cc1e3" 1 9 7 5 "uuid:01ac43f1-4ddb-4ced-8a73-634b1a2cc1e3" 2 8 6 5 "uuid:01ac43f1-4ddb-4ced-8a73-634b1a2cc1e3" 3 5 1 5 "uuid:01ac43f1-4ddb-4ced-8a73-634b1a2cc1e3" 4 4 3 5 "uuid:01ac43f1-4ddb-4ced-8a73-634b1a2cc1e3" 5 7 3 5 "uuid:01ac43f1-4ddb-4ced-8a73-634b1a2cc1e3" 6 1 3 5 "uuid:01b5624d-f98a-4d8f-87f9-db1290070d0d" 1 4 7 2 "uuid:01b5624d-f98a-4d8f-87f9-db1290070d0d" 2 1 7 2 "uuid:01b5624d-f98a-4d8f-87f9-db1290070d0d" 3 3 5 2 "uuid:01c81e19-fb5a-42c8-a05d-d9254d458f6c" 1 1 7 2 "uuid:01c81e19-fb5a-42c8-a05d-d9254d458f6c" 2 8 7 2 "uuid:01c81e19-fb5a-42c8-a05d-d9254d458f6c" 3 2 7 2 "uuid:01e27a70-68e3-43ce-9655-82237b727eb5" 1 8 5 6 "uuid:01e27a70-68e3-43ce-9655-82237b727eb5" 2 5 1 6 "uuid:01e27a70-68e3-43ce-9655-82237b727eb5" 3 1 3 6 "uuid:01e27a70-68e3-43ce-9655-82237b727eb5" 4 4 4 6 "uuid:01e27a70-68e3-43ce-9655-82237b727eb5" 5 3 7 6 "uuid:01e27a70-68e3-43ce-9655-82237b727eb5" 6 9 7 6 "uuid:01e27a70-68e3-43ce-9655-82237b727eb5" 7 7 2 6 end label values q91 fitem2 label def fitem2 1 "Cereals and Grain", modify label def fitem2 2 "Eggs", modify label def fitem2 3 "Fruits", modify label def fitem2 4 "Green leafy vegetables", modify label def fitem2 5 "Meat", modify label def fitem2 6 "Milk and other dairy products", modify label def fitem2 7 "Oil / fat / butter", modify label def fitem2 8 "Pulses and roots", modify label def fitem2 9 "Sugar", modify
Comment