Announcement

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

  • Marginsplot with countries

    Hello all,

    This is just an example: I do a logit-comman like for instance "logit salary gender" where salary is my dependent variable (in $) and gender is my independent variable (0 = female; 1 = male). I then do the "margins, dydx(*)" command followed by "margins, at(gender=(0(1)1))" and marginsplot, recast(scatter)".
    My question is: If i also have a country variable called "country"(where 1 is US; 2 is Canada etc.) what commands should i use to show the difference in salaries (Y) among males and females (X) in different countries in the same marginsplot?

    Thanks alot for the answers

  • #2
    Your example makes no sense, so it confuses me as to what you actually want to do. It makes no sense because you are using a continuous valued variable, salary (in $) as the outcome variable in a logit model. -logit- requires a dichotomous outcome variable: data containing values one might see in a salary variable, when fed to -logit- as the outcome will result in Stata treating it as a dichotomous variable contrasting 0 with anything other than 0. Since salary of 0 is going to be unusual, and maybe even non-existent in a real data set, the analysis is likely to abort with an error message about the outcome not varying. So you will never get to your -margins- command.

    More generally, "if I also have a country variable..." leaves too much to the imagination. Is it simply entered into the command as a covariate, or do you have it interacted with gender (or perhaps with yet another variable or other variables.) Each of these possibilities is associated with different ways to use -margins-, depending on what you specifically want to calculate.

    I suggest that you post back with a specific example that matches what you actually want to do, and be clear about what you want the output of -margins- to tell you about.

    Comment


    • #3
      Sorry, my bad. A specific example: My dependent variable is (Y: Have you participated in political violence during the last 12 month (0 = no; 1 = yes)) and my independent variable is gender (X: 0 is female; 1 is male). I then do a "logit violence i.gender" command (with control variables) followed by "margins, dydx(*)" (to get the predicted probabilities) and "margins, at(gender(0(1)1))" + "margins, recast(scatter)" to show it graphically. I find that women are significantly less likely to participate in political violence.
      My question: I then want to see if this significant difference are present in specific countries. The data is from the Afrobarometer so there are a variable for all 34 african countries (1 is Benin; 2 is Botswana etc.). What command should i use to show the difference in participation among females and males (X) in different countries? An example of what i want it to look like are shown below.


      Attached Files

      Comment


      • #4
        So, first you have to revise your logistic regression command to include i.country##i.gender Once you have done that, I think you want
        [code]
        margins country, dydx(gender)
        marginsplot, recast(scatter)
        [code]

        I don't believe this command will get you the horizontal layout you have: I suppose there are some options you can apply to scatter to make that happen, but I wouldn't know what they are.

        Comment


        • #5
          Thanks a lot for the reply - and sorry again for confusing you

          Have a good day

          Comment


          • #6
            I do the following commands:

            "logit violence i.country##i.gender"
            "margins country, dydx(gender)"
            "marginsplot, recast(scatter)"

            However for all countries it says: (not estimable) and the marginsplot is empty - what is wrong?

            Comment


            • #7
              Here is the output:
              Attached Files

              Comment


              • #8
                I would need a sample of your data to work with to find that out. Use the -dataex- command to post an example. Be sure to choose the example so that it reproduces this problem.

                If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

                Comment


                • #9
                  Okay, thanks. I will try to figureout how -dataex- works

                  Comment

                  Working...
                  X