Announcement

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

  • construction of a variable

    Hello,

    I want to calculate summary statistics of time spent on different activities by husbands and wives. I have variables for time spent on different activities but they are for the head and spouse of the head. For most of the cases, the head is the husband, but for some, the wife is the head. With such a dataset, how can I go about calculating the summary statistics? Please help. An example dataset is attached below.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str35 ind_id_head double(time_spent1_head1 time_spent1_head2) float gender_head str35 ind_id_spouse double(time_spent1_spouse1 time_spent1_spouse2) float gender_spouse
    "TUS10001106201913310301382332001001" 480   0 1 "TUS10001106201913310301382332001002" 300   0 2
    "TUS10001106201913310301382332003001" 420   0 1 "TUS10001106201913310301382332003002"   0   0 2
    "TUS10001106201913310301382332007001"   0   0 1 "TUS10001106201913310301382332007002" 300   0 2
    "TUS10001106201913310301382332009001" 510   0 1 "TUS10001106201913310301382332009002"   0   0 2
    "TUS10001106201913310301382332011001" 360   0 1 "TUS10001106201913310301382332011002" 240   0 2
    "TUS10001106201913310301382332012001"   0   0 1 "TUS10001106201913310301382332012002"   0   0 2
    "TUS10001106201913310301382332013001"   0   0 1 "TUS10001106201913310301382332013002"   0   0 2
    "TUS10002106201911420102221MAN 01001" 360  45 1 "TUS10002106201911420102221MAN 01002" 330   0 2
    "TUS10002106201911420102221MAN 02001" 420  60 1 "TUS10002106201911420102221MAN 02002"   0 210 2
    "TUS10002106201911420102221MAN 04001" 420  45 1 "TUS10002106201911420102221MAN 04002"   0   0 2
    "TUS10002106201911420102221MAN 05001" 360   0 1 "TUS10002106201911420102221MAN 05002"   0  60 2
    "TUS10002106201911420102221MAN 06001" 450  45 1 "TUS10002106201911420102221MAN 06002"   0   0 2
    "TUS10002106201911420102221MAN 07001"   0   0 1 "TUS10002106201911420102221MAN 07002"   0   0 2
    "TUS10002106201911420102221MAN 08001"   0   0 1 "TUS10002106201911420102221MAN 08002"   0   0 2
    "TUS10002106201911420102221MAN 09001" 390  45 1 "TUS10002106201911420102221MAN 09002" 390   0 2
    "TUS10002106201911420102221MAN 10001" 420 120 2 "TUS10002106201911420102221MAN 10002"   0   0 1
    "TUS10002106201911420102221MAN 11001" 465   0 2 "TUS10002106201911420102221MAN 11002" 480   0 1
    "TUS10002106201911420102221MAN 12001" 390  45 2 "TUS10002106201911420102221MAN 12002"   0  30 1
    "TUS10002106201911420102221MAN 13001" 420  50 2 "TUS10002106201911420102221MAN 13002"   0 120 1
    "TUS10002106201911420102221MAN 14001" 540   0 2 "TUS10002106201911420102221MAN 14002" 360   0 1
    end
    Thanks.

  • #2
    Code:
    g time_spent_male1 = time_spent1_head1*(gender_head==1) + time_spent1_spouse1*(gender_spouse==1)
    g time_spent_male2 = time_spent1_head2*(gender_head==1) + time_spent1_spouse2*(gender_spouse==1)
    g time_spent_female1 = time_spent1_head1*(gender_head==2) + time_spent1_spouse1*(gender_spouse==2)
    g time_spent_female2 = time_spent1_head2*(gender_head==2) + time_spent1_spouse2*(gender_spouse==2)
    
    summ time_spent_*

    Comment


    • #3
      Thank you, George.

      Comment

      Working...
      X