Announcement

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

  • Logistic Regression with categorical predictor

    Good afternoon everyone,

    I'm pretty new with Stata. I'm using Stata version 12.

    I'm interested in logistic regression. I'm analyzing a logistic regression with main effects and interaction. My question is related to the interaction between two variables: "socialassistance" and "education". Both of them are categorical variables. I want to analyze this interaction step by step. This is because I use "i." However, my problem is the following: when I write:

    xi: logit selfemployment i.socialassistance*i.education

    I cannot execute the action. I have this problem:

    "Unknown egen function group ()"

    I don't know what can I do. I would greatly appreciate your help.

    Thank you in advance.

    Best wishes,
    Luisa



  • #2
    I don't know what is causing your error. But since you are using Stata 12, you should take advantage of factor variables. Something like

    Code:
    logit selfemployment i.socialassistance i.education i.socialassistance#i.education
    I also don't know what you mean by "step by step," but you might want to first estimate a model without the interaction and then estimate the above model.
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    StataNow Version: 18.5 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      Luisa,

      Presumably you are using the egen command. Post the complete/exact code and output that seems relevant to the error you report.

      I thought it could be you leaving a blank space between group and (). But after testing I figure it works even with the spacing.
      Last edited by Roberto Ferrer; 22 Apr 2014, 12:57.
      You should:

      1. Read the FAQ carefully.

      2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

      3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

      4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

      Comment


      • #4
        Roberto,

        I think the egen group() error comes from the use of xi: (look at xi.ado and search for egen; it's used to create levels for categorical variables). I'm not sure, though, why it would give such an error unless her Stata installation is corrupted.

        I'm also not sure how she got away with specifying her interaction as i.socialassistance*i.education, so perhaps there is more to this problem than meets the eye.

        Regards,
        Joe

        Comment


        • #5
          Originally posted by Joe Canner View Post
          I think the egen group() error comes from the use of xi: (look at xi.ado and search for egen; it's used to create levels for categorical variables).
          Good point Joe. Luisa still needs to show her exact input if she wants to increase the probability of receiving help.

          Originally posted by Joe Canner View Post
          I'm also not sure how she got away with specifying her interaction as i.socialassistance*i.education
          Can I ask what's the problem with this?
          Last edited by Roberto Ferrer; 22 Apr 2014, 16:24.
          You should:

          1. Read the FAQ carefully.

          2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

          3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

          4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

          Comment


          • #6
            As I understand it, Stata does not permit using an asterisk to specify interactions. When I tried it on my Stata 12.1, I got an error like "variable i.x1*i.x2 not found". Am I missing something?

            Comment


            • #7
              Originally posted by Joe Canner View Post
              As I understand it, Stata does not permit using an asterisk to specify interactions. When I tried it on my Stata 12.1, I got an error like "variable i.x1*i.x2 not found". Am I missing something?
              I believe the asterisk is correct with the old -xi- command but not with today's factor variables.

              I haven't been able to reproduce the original error, which leads me to believe that something important has been omitted or that the installation of Stata is corrupted.
              -------------------------------------------
              Richard Williams, Notre Dame Dept of Sociology
              StataNow Version: 18.5 MP (2 processor)

              EMAIL: [email protected]
              WWW: https://www3.nd.edu/~rwilliam

              Comment


              • #8
                Originally posted by Joe Canner View Post
                As I understand it, Stata does not permit using an asterisk to specify interactions.
                help xi states

                Syntax

                xi [, prefix(string) noomit] term(s)

                xi [, prefix(string) noomit] : any_stata_command varlist_with_terms ...

                where a term has the form

                i.varname or I.varname
                i.varname1*i.varname2 I.varname1*I.varname2
                i.varname1*varname3 I.varname1*varname3
                i.varname1|varname3 I.varname1|varname3
                and offers the following example:

                . xi: logistic outcome weight bp i.agegrp*i.race
                You should:

                1. Read the FAQ carefully.

                2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

                3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

                4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

                Comment


                • #9
                  Ahh, that make sense. I did use xi: to test this syntax and it ran OK and I couldn't figure out why (I'm new to Stata since xi was phased out). Then I ran it without xi: and got the error mentioned above. It didn't occur to me to check the xi: documentation.

                  Never mind then...

                  Comment


                  • #10
                    Hello again,

                    First of all, thank you so much for your help. I'm PhD student and it's the first time I use Stata.

                    Following Roberto´s advice, I'm going to explain my exact input. I'm researching the influence of credits on entrepreneurship. This relationship is mediated and moderated by two categorical variables: social assistance and education. Social assistance is a categorical variable (from 1 to 5) and it is a mediating variable. Education is another categorical variable (from 1 to 9) and it is a moderating variable. I want to develop a logistic regression. In this logistic regression, I have to calculate the interaction between social assistance and education. Moreover, I want to see this interaction for each value of each categorical variable. For example, basiceducation*socialassistance1
                    basiceducation*socialassistance2
                    basiceducation*socialassistance3
                    This is because I use the option: i.socialassistance*i.education

                    I did it with "xi" and without "xi". In both cases I did not get anything.

                    Thank you again for your help.

                    Comment


                    • #11
                      Hi Luisa,

                      By "exact input" I meant the exact relevant code as typed in the command window or .do file. Inferring what happened from that one initial command and error you posted seems difficult, at least to me. Can you reproduce this error using a small sample of your data? Can you post it? What is the code that comes before the xi: logit? Have you tried Richard's suggestion of using factor variable notation (see help factor variables) ?

                      Advice on Posting from the FAQ states:

                      12. Be informative about commands and data and give examples

                      Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly! If you can, reproduce the error with one of Stata's provided datasets, a small fragment of your dataset, or a simple concocted dataset that you include in your posting. If you are using user-written commands, explain that and say where where they came from: the Stata Journal, SSC, or other archives. This helps (often crucially) in explaining your precise problem, and it alerts readers to commands that may be interesting or useful to them.
                      You should:

                      1. Read the FAQ carefully.

                      2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

                      3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

                      4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

                      Comment


                      • #12
                        I have just got it. Thank you so much!

                        Effectively Roberto, I saw Richard's suggestion again and I have realized that instead of using #, I was using the asterisk.

                        Now, everything is fine.

                        Comment


                        • #13
                          Glad it worked out.

                          But maybe the xi: should have worked also. Consider troubleshooting your original code here in Statalist. There's a small chance it could be some bug.
                          You should:

                          1. Read the FAQ carefully.

                          2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

                          3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

                          4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

                          Comment


                          • #14
                            I tested with xi: but it didn't work.

                            Comment


                            • #15
                              Originally posted by Luisa Márquez View Post
                              I tested with xi: but it didn't work.
                              If I understand correctly, you solved the problem using factor variable notation, as suggested by Richard. That's just fine. But my previous post was about finding out why xi: was giving the error you mentioned in your opening post. You didn't give enough information to solve that particular problem.
                              You should:

                              1. Read the FAQ carefully.

                              2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

                              3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

                              4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

                              Comment

                              Working...
                              X