Announcement

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

  • using factor variables in: estimates table ... , keep(...)

    Dear Statalisters,

    I have difficulties using the estimates table command with the keep() option and factor variables under Stata 13.1. I noticed, that if I set the base level of the factor variable to none, I get the following error message when running the . estimates table ..., keep(i.factor) command:
    coefficient i.factor does not occur in any of the models

    To make things clear, here is an example illustrating my problem:


    Code:
    sysuse auto
    drop if rep78 == .
    
    fvset base none rep78
    
    reg price length weight i(2 3 4).rep78, nocon
    estimates store est1
    
    reg price length weight trunk i(2 3 4).rep78, nocon
    estimates store est2
    
    estimates table est*, keep(length weight trunk i.rep78) equations(1)
    coefficient i.rep78 does not occur in any of the models


    I noticed that if I do not set the base level, the problem is gone. However unfortunately I need to run the regression with no base level. Setting the base level mid-regression (ibn.rep78) also solves the problem, but it is not an option because I want to specify which levels to use (2 3 4 in this example, given as a macro in the real script). Also, I must to use the keep option, because the order of the variables is important for exporting the coefficients and further manipulation by other software.

    A similar problem arose in this thread too. estout was recommended solution there. That might work, but I would like to consider that as a last resort option, because I work in a corporate environment, and installing user written programs can be problematic.

    I know that my needs are quite specific, and that many otherwise good workarounds are not possible because of those, so a solution would not be of much use for many people. In spite of this I would really appreciate if some of you could give it some thought.

    Best regards,
    Martin Stancsics
    Last edited by Martin Stancsics; 06 Aug 2014, 08:13. Reason: formatted for better readibility

  • #2
    I noticed that if I do not set the base level, the problem is gone. However unfortunately I need to run the regression with no base level. Setting the base level mid-regression (ibn.rep78) also solves the problem, but it is not an option because I want to specify which levels to use (2 3 4 in this example, given as a macro in the real script).
    This is absolutely possible. Try

    Code:
    loc levels 2 3 4
    reg price length weight i(`levels')bn.rep78 ,nocon
    Best
    Daniel
    Last edited by daniel klein; 06 Aug 2014, 07:59.

    Comment


    • #3
      Dear Daniel,

      Thank you for the quick answer. Indeed, it is possible, and it solved my problem.

      I have mistakenly tried using ibn(`levels').rep78 which is apparently incorrect syntax, so it did not work

      Thanks again!

      Regards,
      Martin.

      Comment


      • #4
        I got similar problem

        Code:
        global est_spe age age2 i.edu_att gender marriage party_state professional clerical third_industry protitle wunitcha party health
        quietly reg income $est_spe du_prov* if rural==0&work==1, vce(robust)
        est sto income_ols_prov
        predict income_ols_prov,xb
        *compare models with and without prov* control
        estimates table income_ols income_ols_prov,drop(du_prov*) b t stats(N r2) b(%5.2f)
        Not matter use -keep()- or --drop-- ,they all gave me the coefficient does not occur error
        Does the --quietly-- is to blame? I cannot access to the data, I write code and let some insiders run it for me, so it's cumbersome to get immediate reply and debug the problem.
        Last edited by Zhang_Lu; 15 Jan 2015, 04:36.

        Comment


        • #5
          any suggestion?

          Comment


          • #6
            Try putting the list of du_prov* variables in a macro, and reference this macro in your model
            fit and call to estimates table. This macro is quickly created using the unab command.

            Code:
            global est_spe age age2 i.edu_att gender marriage party_state professional clerical third_industry protitle wunitcha party health
            unab prov_list : du_prov*
            quietly reg income $est_spe `prov_list' if rural==0&work==1, vce(robust)
            est sto income_ols_prov
            predict income_ols_prov,xb
            *compare models with and without prov* control
            estimates table income_ols income_ols_prov,drop(`prov_list') b t stats(N r2) b(%5.2f)

            Comment


            • #7
              Originally posted by Jeff Pitblado (StataCorp) View Post
              Try putting the list of du_prov* variables in a macro, and reference this macro in your model
              fit and call to estimates table. This macro is quickly created using the unab command.

              Code:
              global est_spe age age2 i.edu_att gender marriage party_state professional clerical third_industry protitle wunitcha party health
              unab prov_list : du_prov*
              quietly reg income $est_spe `prov_list' if rural==0&work==1, vce(robust)
              est sto income_ols_prov
              predict income_ols_prov,xb
              *compare models with and without prov* control
              estimates table income_ols income_ols_prov,drop(`prov_list') b t stats(N r2) b(%5.2f)
              That works, though I don't understand why I can't use the wildcard * in the option, after all I have generated the prov variables in the dataset. Is it true that I have to create a macro when putting a list of dummies into the option (not just --drop()-- but similar options)?
              Futhermore, is the macro global or local, should I create repeatly in different sub-dofiles?
              Last edited by Zhang_Lu; 15 Jan 2015, 19:27.

              Comment


              • #8
                The documentation in [R] estimates table for keep() and drop() specify what is allowed as an argument.
                These options take a coeflist, which is documented as

                A coeflist is a list of coefficient names, each name of which may be simple (for
                example, price), an equation name followed by a colon (for example, mean:), or a
                full name (for example, mean:price). Names are separated by blanks.
                This is not the same as a varlist, which generally allows wildcard characters like *.

                The unab command creates a local macro.

                Comment


                • #9
                  Really appreciate your helpful suggestion

                  Comment

                  Working...
                  X