Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating indicator variable that shows if food choices in HH were made by male or female individual

    Dear Statalists,
    I am writing my thesis. Currently, I want to check out if one of my independent variables varies enough to conduct an analysis. To do so, I obviously have to construct that variable. The variable shall be a dummy variable indicating if the person that is responsible for food purchases of the household is female (1) or male (0).
    The dataset is an unbalanced panel dataset with t=2 and I am using Stata 16.1.
    I have the following information that should suffice to construct the variable, but I don't know how exactly and starting to get a bit mad after trying and searching for an answer for too long:

    - hhid (household identifier)
    - membid (identifier of household member)
    - sex (female=1)
    - respshop (membid of the person that is responsible for shopping)

    Here you can find my dataex:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long hhid double membid int year float(sex respshop)
    101015 1 2012 1 1
    101045 1 2012 0 2
    101060 2 2012 1 2
    101075 1 2012 0 2
    101075 2 2012 1 2
    101092 2 2015 1 2
    101092 2 2012 1 2
    101105 2 2012 1 2
    101120 1 2012 1 1
    101125 1 2015 0 1
    101133 2 2015 1 2
    101150 1 2012 0 2
    101150 2 2012 1 2
    101152 1 2015 0 1
    101152 2 2015 1 1
    101160 1 2015 0 3
    101160 3 2015 1 3
    101165 1 2012 1 1
    101180 1 2012 0 1
    101187 1 2015 1 1
    101232 2 2015 1 2
    101233 1 2015 1 1
    102012 1 2012 0 2
    102012 2 2012 1 2
    102042 1 2012 1 1
    102042 1 2015 1 1
    102057 1 2012 0 1
    102072 1 2012 1 1
    102117 1 2012 0 1
    102147 1 2012 0 1
    102177 1 2012 0 1
    102192 2 2012 1 2
    102198 1 2012 0 1
    102207 1 2012 0 1
    102224 1 2012 0 2
    102224 2 2012 1 2
    102224 2 2015 1 2
    102235 1 2015 0 2
    102235 2 2015 1 2
    102237 1 2015 0 2
    102237 1 2012 0 2
    102237 2 2015 1 2
    102237 2 2012 1 2
    102238 1 2015 0 2
    102238 2 2015 1 2
    102242 2 2015 1 2
    102248 1 2015 0 2
    102248 2 2015 1 2
    102251 2 2015 1 2
    102252 2 2012 1 2
    102253 2 2015 1 2
    102255 2 2015 1 2
    102258 2 2015 1 2
    102259 1 2015 0 2
    102259 2 2015 1 2
    102261 1 2015 1 1
    102262 1 2015 1 1
    103005 1 2015 0 2
    103005 1 2012 0 2
    103005 2 2012 1 2
    103005 2 2015 1 2
    103020 1 2012 0 2
    103020 2 2012 1 2
    103020 2 2015 1 2
    103035 1 2012 0 2
    103035 2 2012 1 2
    103050 1 2012 0 1
    103050 1 2015 0 1
    103079 2 2015 1 2
    103079 2 2012 1 2
    103094 2 2012 1 2
    103109 1 2012 0 1
    103270 1 2015 0 2
    103270 2 2015 1 2
    103273 2 2015 1 2
    103286 1 2015 1 1
    104011 1 2015 0 2
    104011 2 2015 1 2
    104014 1 2015 0 2
    104014 1 2012 0 2
    104014 2 2012 1 2
    104014 2 2015 1 2
    104023 1 2015 1 1
    104028 1 2015 0 2
    104028 2 2015 1 2
    104038 2 2015 1 2
    104045 1 2012 0 2
    104045 2 2012 1 2
    104045 2 2015 1 2
    104051 2 2015 1 2
    104053 1 2015 1 1
    104058 1 2015 0 2
    104058 2 2015 1 2
    104059 1 2015 0 1
    104059 1 2012 0 1
    104061 1 2015 1 1
    104071 2 2015 1 2
    104073 2 2015 1 2
    104083 1 2015 0 2
    104083 2 2015 1 2
    end
    label values year year
    I would really appreciate your help also if this might be very trivial for some of you, as I am currently stuck.
    Kind regards, Jacob

  • #2
    Code:
    egen female_resp = max(sex & resp), by(hhid year)
    will be 1 if any female is responsible and 0 otherwise,

    Notes:

    1. The code won’t check if a male as well as a female is declared responsible.

    2. Your specification does not spell out whether you want to treat years separately, as I have guessed here. If you don’t, leave out year from the code.

    Comment


    • #3
      Thank you so so much! You made my day . To be honest I just did not think about using the max command for two variables at the same time...

      Comment

      Working...
      X