Announcement

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

  • Combining a newly constructed dummy variables to one categorical variable for analysis/refcat

    Dear Statalist,

    I have currently created four variables about family status: 1) Parents living together 2) Shared custody 3) Lonley parent 4) Living with a step parent/new family. They act as four dummys where 0 = different status 1 = actual status. My challenge is to combine these together.

    Talking to my advisor she told me it would be more wise to group them together and use one of them as a reference category. I assume the best way to do this is to run the final, combined categorical variable as a factor variable and write b1.familystatus in the regression.After much googling and Statalisting I do not manage to find exactly what I look for.

    So far I have tried the egen group-function (egen newvar = group (var1 var2 var3 var4)) but this gives me more categories than expected/a combination of the combinations I guess.

    Has anyone come across this dilemma before?


    Thanks a lot in advance.


    Best regards,
    Jonas.



    If it was unclear: I have 4 pie charts where each just show 0 or 1 (50,50 split), while I want a more nuanced pie chart with all the combinations (25% split).

  • #2
    Jonas:
    I sponsor your supervisor's advice:
    Code:
    set obs 4
    g id=_n
    g Parents_living_together=1 in 1
    replace Parents_living_together=0 if Parents_living_together==.
    g Shared_custody=1 in 2
    replace Shared_custody=0 if Shared_custody==.
    g Lonely_parent=1 in 3
    replace Lonely_parent=0 if Lonely_parent==.
    g Step_parent_new_family=1 in 4
    replace Step_parent_new_family=0 if Step_parent_new_family==.
    egen Living_status=group(Parents_living_together Shared_custody Lonely_parent Step_parent_new_family)
    label define Living_status 4 "Parents_living_together" 3 "Shared_custody" 2 "Lonely_parent" 1 "Step_parent_new_family"
    label val Living_status Living_status
    list
    
         +--------------------------------------------------------------------------+
         | id   Parent~r   Shared~y   Lonely~t   Step_p~y             Living_status |
         |--------------------------------------------------------------------------|
      1. |  1          1          0          0          0   Parents_living_together |
      2. |  2          0          1          0          0            Shared_custody |
      3. |  3          0          0          1          0             Lonely_parent |
      4. |  4          0          0          0          1    Step_parent_new_family |
         +--------------------------------------------------------------------------+
    
    .
    For your regression, see -fvvarlist- as far as categorical varaibles and interaction creation is concerned.
    As an aside, it is always recommended to have a 0 level in categorical variable. In the toy-example reported above I did not respect this rule, being aware that Stata, during -regress-, will renumber the levels of the categorical variable as requested.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      (deleted, crossed in the ether with Carlo's posting)

      Comment


      • #4
        Dear Carlo and Mike

        Thank you for your fast replies. The practical example helped me understand more how this command works. I did once again encounter my error with more categories than expected. By going to data editor I selected the above mentioned variables alongside the new family status. I had duplicates where (of course) one can live with a step-parent AND have shared custody simultaneously. There were also a few who did not fit into these categories - such as institutions etc/mixed category. So of course the command gave me more than expected.

        You guys at Statalist is super and I learn so much - thanks again and have a great weekend!


        Best regards,
        Jonas.

        Comment


        • #5
          Hi, I'm trying Carlo's code. I can't start from set obs, in my case it is "set obs 10", but I have an error (r198). Help me, please.

          Comment


          • #6
            Irieleth:
            welcome to this forum.
            Unfortunately, I cannot replicate your error:
            Code:
            . set obs 10
            number of observations (_N) was 0, now 10
            
            .
            As per r(198), you should check the syntax of your code(s).
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment

            Working...
            X