Dear users,
I have the data below. It is already in long format and the ID variable named `survey_id` is already duplicated in some households. My aim is to merge group 1 with group2 so that group 2 goes below group 1 and I will have just one variable called group.
I have tried to reshape long but I get an error of unique ID. I tried stack and it creates something a bit weird
What I need is as on this table below.
From this:
survey_id group1 group2
1 milk
1 grain pulse
1 grain pulse
2 milk
2 milk pulse
To This:
I have the data below. It is already in long format and the ID variable named `survey_id` is already duplicated in some households. My aim is to merge group 1 with group2 so that group 2 goes below group 1 and I will have just one variable called group.
I have tried to reshape long but I get an error of unique ID. I tried stack and it creates something a bit weird
What I need is as on this table below.
From this:
survey_id group1 group2
1 milk
1 grain pulse
1 grain pulse
2 milk
2 milk pulse
To This:
survey_id | group |
1 | milk |
1 | grain |
1 | pulse |
1 | grain |
1 | pulse |
2 | milk |
2 | milk |
2 | pulse |
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str21 survey_id str44 group1 str32 group2 "0111333496-261023" "Others" "0111333496-261023" "Other vegetables" "0111333496-261023" "Other vegetables" "0111333496-261023" "Others" "0111333496-261023" "Grains, white roots and tubers and plantains" "0111333496-261023" "Others" "0111333496-261023" "Others" "0111333496-261023" "Other vegetables" "0111333496-261023" "Other vegetables" "0111333496-261023" "Dark green leafy vegetables" "0111333496-261023" "Grains, white roots and tubers and plantains" "0111333496-261023" "Others" "0111333496-261023" "Others" "0111333496-261023" "Milk and Dairy Products" "0112183531-091123" "Dark green leafy vegetables" "0112183531-091123" "Other vegetables" "0112183531-091123" "Other vegetables" "0112183531-091123" "Others" "0112183531-091123" "Others" "0112183531-091123" "Grains, white roots and tubers and plantains" "0112183531-091123" "Other vegetables" "0112183531-091123" "Others" "0112183531-091123" "Others" "0112183531-091123" "Other vegetables" "0112183531-091123" "Grains, white roots and tubers and plantains" "0112183531-091123" "Grains, white roots and tubers and plantains" "0112183531-091123" "Others" "0112183531-091123" "Others" "0112183531-091123" "Milk and Dairy Products" "0112183531-311023" "Other vegetables" "0112183531-311023" "Other vegetables" "0112183531-311023" "Others" "0112183531-311023" "Others" "0112183531-311023" "Dark green leafy vegetables" "0112183531-311023" "Grains, white roots and tubers and plantains" "0112183531-311023" "Other vegetables" "0112183531-311023" "Others" "0112183531-311023" "Other vegetables" "0112183531-311023" "Others" "0112183531-311023" "Dark green leafy vegetables" "0112183531-311023" "Grains, white roots and tubers and plantains" "0112183531-311023" "Others" "0112183531-311023" "Others" "0112183531-311023" "Milk and Dairy Products" "0112823730-111123" "Others" "0112823730-111123" "Others" "0112823730-111123" "Other vegetables" "0112823730-111123" "Other vegetables" "0112823730-111123" "Other vegetables" "0112823730-111123" "Others" "0112823730-111123" "Others" "0112823730-111123" "Grains, white roots and tubers and plantains" "0112823730-111123" "Others" "0112823730-111123" "Others" "0112823730-111123" "Other vegetables" "0112823730-111123" "Other vegetables" "0112823730-111123" "Dark green leafy vegetables" "0112823730-111123" "Grains, white roots and tubers and plantains" "0112823730-111123" "Others" "0112823730-111123" "Others" "0112823730-111123" "Milk and Dairy Products" "0113375472-071123" "Others" "0113375472-071123" "Others" "0113375472-071123" "Other vegetables" "0113375472-071123" "Other vegetables" "0113375472-071123" "Other vegetables" "0113375472-071123" "Others" "0113375472-071123" "Others" "0113375472-071123" "Grains, white roots and tubers and plantains" "0113375472-071123" "Others" "0113375472-071123" "Others" "0113375472-071123" "Other vegetables" "0113375472-071123" "Other vegetables" "0113375472-071123" "Other vegetables" "0113375472-071123" "Others" "0113375472-071123" "Others" "0113375472-071123" "Grains, white roots and tubers and plantains" "0113375472-071123" "Others" "0113375472-071123" "Others" "0113375472-101123" "Others" "0113375472-101123" "Others" "0113375472-101123" "Others" "0113375472-101123" "Other vegetables" "0113375472-101123" "Other vegetables" "0113375472-101123" "Others" "0113375472-101123" "Dark green leafy vegetables" "0113375472-101123" "Grains, white roots and tubers and plantains" "0113375472-101123" "Others" "0113375472-101123" "Others" "0113375472-101123" "Milk and Dairy Products" "0113737613-131123" "Others" "0113737613-131123" "Others" "0113737613-131123" "Dark green leafy vegetables" "0113737613-131123" "Grains, white roots and tubers and plantains" "0113737613-131123" "Others" "0113737613-131123" "Others" "0113737613-131123" "Others" "0113737613-131123" "Others" "0113737613-131123" "Grains, white roots and tubers and plantains" "0113737613-261023" "Others" end
Comment