Announcement

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

  • Problems with statsby and logit

    Hello,

    I am new to Stata and I have a question for which I can not find a solution online. Any help would be highly appreciated

    I have to replicate a regression table where the regression coefficients are obtained by averaging the coefficients from annual logit regressions over a given sample period. My sample consists of 21,534 firm-year observations (panel data).

    I tried to compute the values by using the statsby-command. Unfortunately, Stata freezes when I enter the following code:

    use "UK_reg", clear

    statsby _b, by(fyear) verbose nodots: logit payers pcrank mb growth prof1 ecem

    list

    sum _b_pcrank
    sum _b_mb
    sum _b_growth
    sum _b_prof1
    sum _b_ecem

    However, if I replace "logit" by "reg", I obtain the desired results. How can I get my code working for "logit"?

    Thank you very much in advance for your help.

    Regards,

    Adriana

  • #2
    There is nothing obviously wrong with the code you show. I have never encountered a situation like this. Where does Stata freeze? During the -statasby- command, or one of the others? Are there any error messages? Generally speaking you should show not just the commands you gave but the exact output you got from Stata. The best way to do that is to copy directly from the Results window or your log file and paste it between code delimiters here on the Forum (so that the output aligns nicely).

    If it works with -reg- but not -logit-, one possibility that arises is this: is your variable payers coded 0/1, and do both 0 and 1 values occur in the data in each fyear?

    Comment


    • #3
      Dear Clyde,

      thank you for your quick response. Stata freezes during the -statsby- command. No error message occurs.

      Yes, my variable payers is coded 0/1 and both values occur in the data in each year. (Payers equals 1, if the firm pays dividends in the given year and 0 otherwise.)




      Comment


      • #4
        One other thought. What happens if you just run the logit for the entire data set, without -statsby-? Do you get any error message then? I'm thinking that perhaps one of your predictor variable provides perfect prediction of outcome. If the -logit- runs on the entire data set, then try running -by(fyear), sort: lgoit payers pcrank mb growth prof1 ecem- to see if -logit- alone will run on each subset of the data. See if you turn up some error messages that way. (I'm not optimistic this will work: normally if there is an error like this, -statsby- will stop with an error message, or even run through all the fyear groups and then tell you that it couldn't actually calculate coefficients for any of the groups.)

        If none of this leads to a solution, I can't think of any good reason you should -statsby- should freeze Stata. First I would make sure your Stata installation is completely up to date and not corrupted. Run -update all, force- and try again.* If it still does the same thing, then I would contact Stata technical support about this.

        *If you are on a network that you do not control, you may not be able to update Stata. If there are firewall issues, the -update- will fail with an error message. On some networks it is more subtle: the -update- appears to run, but the network actually redirects you from Stata's site to a cached copy of a now out-of-date Stata version. It looks like the -update- worked, but you still have an out-of-date Stata. The way to be sure your update actually worked is to run -about- after the -update-. As of today, the latest update date for version 14 is 16 Nov 2016. If Stata tells you you have something older than that, then you did not get a real update. In that case, contact your IT administrator and ask them to enable you to do a real update.

        Comment


        • #5
          If I run
          Code:
          logit payers pcrank mb growth prof1 ecem
          the regression doesn't converge.

          But with the following Code
          Code:
          bysort fyear: logit payers pcrank mb growth prof1 ecem
          I have no problems.

          Unfortunately, I am not able to update Stata. There are some issues with the connection because I access Stata online through my university software.

          . update all, force
          (contacting http://www.stata.com)
          connection timed out -- see help r(2) for troubleshooting
          http://www.stata.com did not respond or is not a valid update site
          r(2);
          Is there maybe an alternative way to obtain the data I need? I mean, an alternative to using -statsby-?

          Thank you very much for your effort.

          Comment


          • #6
            Well, the following code is more or less what -statsby- does, with the setup customized to your data and with some error-checking removed. But since you can run the logit for each fyear without a problem, this should be a reasonable workaround:

            Code:
            tempfile coefficients
            capture postutil clear
            postfile handle int fyear float _b_pcrank _b_mb _b_growth _b_prof1 ///
                _b_ecem using `coefficients'
            
            levelsof fyear, local(fyears)
            foreach f of local fyears {
                logit payers pcrank mb growth prof1 ecem if fyear == `f'
                post handle (fyear) (_b[pcrank]) (_b[mb]) (_b[growth]) (_b[prof1]) ///
                    (_b[ecem])
            }
            postclose handle
            
            use `coefficients', clear
            
            summ __b*
            That said, the error you got trying to update Stata suggests that your network is blocking access to the Stata website because your university is providing Stata for you and probably has one installation with a network license. So I think you should contact your IT administrator and report this problem to him/her. There is no good reason you should be unable to use -statsby- when you can run the -logit- separately in each year. Something must be wrong with your Stata installation, and who knows what other commands may fail, or even appear to run but produce wrong results. So I would push them to get it taken care of.

            Note: Because I do not have your data set, I am unable to test this code. Beware of typos or other small errors.

            Comment


            • #7
              Hello Clyde,

              thank you so so much!! The code works and produces exactly the results I wanted! This problem was giving me sleepless nights. I am very grateful to you.

              I have contacted my university twice because of the blocked access but I didnt get any response. I am also not able to install programmes from ssc and stata is crashing frequently...

              Thank you once again and best regards,

              Adriana


              Click image for larger version

Name:	image1 (1).JPG
Views:	1
Size:	1.86 MB
ID:	1367368
              Last edited by Adriana Rosalia Ernst; 10 Dec 2016, 18:43.

              Comment


              • #8
                Notwithstanding that Clyde has solved the immediate problem: My first tack in diagnosis here would be to -set trace on- and run the code that led to a freeze. I think there is a chance (not high but non-zero :-}) that -statsby- will show something in the trace to indicate where the problem lies, and whether an installation problem is at fault. StataCorp's tech support people can't completely duplicate the conditions on your machine, installation of Stata, etc., so having a trace from your machine would useful data for them, and even perhaps for one of us. Opening a log file prior to the trace would be good, too.

                Comment


                • #9
                  Good points, Mike!

                  Comment


                  • #10
                    With regards to downloading and installing files from SSC --

                    You presumably have something you have read/write access to. So, you can change Stata's directories to be on that drive. Notre Dame users in public labs can't write to the C: drive but they do have read/write access to the N: drive for their own files. So, the directories that Stata uses can be switched to the N: drive. The critical commands (you can add more if you want) are

                    * These commands personalize your Stata directories.
                    * You need to create these directories first.
                    sysdir set OLDPLACE N:\ado
                    sysdir set PERSONAL N:\ado\personal
                    sysdir set PLUS N:\ado\plus

                    I place these commands in N:\mystata.do. Then, after starting Stata, I type

                    run N:\mystata

                    Unfortunately, you are still at the mercy of your tech people to get Stata itself updated for you.
                    -------------------------------------------
                    Richard Williams, Notre Dame Dept of Sociology
                    StataNow Version: 19.5 MP (2 processor)

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

                    Comment


                    • #11
                      Thank you everyone for your advice! I'll try it out

                      Comment

                      Working...
                      X