Announcement

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

  • Issue: re-normalize fixed-effects after regressions. Q: Any way to speed up the "contrast" command?

    Dear Stata users:

    I use “contrast” to normalize fixed-effects to grand mean and compute corresponding standard errors after “regress” command. After 13 days, no results come up yet. Would really appreciate if you can help me out. Thank you in advance for your help. Below are more details,

    Task: normalize fixed-effects to grand mean and compute corresponding standard errors
    Simplified Model: Y=aX+bW+u, where W represents a set of dummies
    Data size: 205 MB
    Commands:
    1. stage 1: obtain fixed-effects
      1. codes: regress y X i.W [aw=weights]
      2. it takes about 2 hours
      3. there are about 7000 dummies (W)
    2. stage 2: normalize fixed-effects to grand mean
      1. codes: parmby "contrast gw.W, post"
      2. Not results after 13 days
    Questions
    1. Is there any way to speed up the "contrast" command?
    2. felsdvregdm might be faster than contrast. But my understanding is it does not allow for weights. So it will not work here.
    3. Should I consider any other commands besides "contrast" or " felsdvregdm"?
    4. I have dropped unused data, unnecessary variables, compress the data set, and reduce maximum matrix size and variable size as much as possible. In general, is there any other way to speed up computation?

    Version of stata: StataMP 14 (64-bit)

    Any thought would be highly appreciated!

    Lihan
    Last edited by Lihan Liu; 17 Jan 2017, 15:25.

  • #2
    Lihan:
    have you already taken a look at -areg-?
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Here is one way without standard errors :

      Code:
      // open some example data
      sysuse nlsw88, clear
      
      // this is what you did
      reg wage hours i.occupation
      contrast gw.occupation
      
      // alternative
      xtreg  wage hours, i(occupation) fe
      predict u, u
      table occupation, c(mean u)
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Originally posted by Carlo Lazzaro View Post
        Lihan:
        have you already taken a look at -areg-?
        Dear Carlo, thank you for your reply. I did considered "areg". However, contrast does not work after "areg".

        For example:

        // open some example data
        sysuse nlsw88, clear

        // use areg
        areg wage hours, absorb(occupation)
        contrast gw.occupation
        stata erros: variable occupation not found

        Comment


        • #5
          Originally posted by Maarten Buis View Post
          Here is one way without standard errors :

          Code:
          // open some example data
          sysuse nlsw88, clear
          
          // this is what you did
          reg wage hours i.occupation
          contrast gw.occupation
          
          // alternative
          xtreg wage hours, i(occupation) fe
          predict u, u
          table occupation, c(mean u)
          Dear Maarten, thank you very much for your suggestion. It is great to know! I do need standard errors. Plus xtreg does not work in my case because I have weights which vary within group.

          Comment


          • #6
            Update: I wrote my own codes to compute point estimates and standard errors. It is much faster than "contrast" command. Seems the "contrast" command computes a lot more things, which I don't need. In one experiment, my codes take 7min. However, the contrast command takes 1Hour and 20 min.

            The problem is solved. Thank everyone for your help!

            Comment


            • #7
              FYI, specify "nowald" and "noeffect" did speed up "contrast". But still it is slow.

              Comment


              • #8
                Lihan Liu : Can you share your code for calculating grand weighted mean contrasts with standard errors?
                I agree that contrast gw. is very slow.

                Comment

                Working...
                X