Announcement

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

  • EFA/CFA for Panel Data

    Hi everyone,
    I'm encountering issues with running panel CFA/EFA. I have a dataset of ~150.000 observations of S&P 1500 companies from 2002-2019 (COMPUSTAT data).
    From what I've seen, there are several ways to do this.
    1) When I ran GSEM using group(fyear) as a variable, it gets stuck on refining starting values and just keeps running with no effect.
    2) The other option I found was running glamm, however I cannot figure out if this is even viable and if yes, how to specify which variables are latent and how to specify the using panel data (I assumed using group(fyear) would work).

    To be more precise, I have 11 variables (like ROE, ROA etc) and I'm interesting on how many factors they load.
    I ran normal factor varlist, pcf and found 4 factors (5th is marginal), but I am interested in seeing how they load while taking into account time component (which from my understanding this function does not do).

    3) I found a function called xtdpml, but again I cannot figure out how to specify latent variables.

    Thus, I have two questions:
    1) Which method is the best taking into account the panel structure and number of observations?
    2) In the best model, how to specify the model to include latent variables?

    Thank you!

  • #2
    Any advice on this please?

    Comment


    • #3
      Originally posted by John Schawrz View Post
      I have 11 variables (like ROE, ROA etc) and I'm interesting on how many factors they load.
      Try performing factor analysis separately each year. If the factor structure is stable, then with that many observations it should show up as such in terms of how many factors are warranted. Run the code below, where a stable orthogonal three-factor structure is illustrated in a dataset that has key features that you describe for yours.
      Code:
      version 16.0
      
      clear *
      
      set seed `=strreverse("1526372")'
      
      quietly set obs `=floor(15000 / 18)'
      generate int pid = _n
      quietly expand 18
      bysort pid: generate byte tim = _n
      
      tempname Corr
      matrix define `Corr' = J(3, 3, 0.5) + I(3) * 0.5
      drawnorm v1 v2 v3, double corr(`Corr')
      drawnorm v4 v5 v6, double corr(`Corr')
      drawnorm v7 v8 v9, double corr(`Corr')
      drawnorm v10 v11 v12, double corr(`Corr')
      drop v12
      
      *
      * Begin here
      *
      tempname Eigenvalues
      forvalues tim = 1/18 {
          quietly factor v* if tim == `tim'
          matrix define `Eigenvalues' = (nullmat(`Eigenvalues') \ e(Ev))
      }
      
      contract tim, freq(count)
      svmat double `Eigenvalues', names("Ev")
      format Ev* %03.1f
      
      list tim E*, noobs separator(0)
      
      exit
      If the factor structure isn't stable over time, then I'm not sure that incorporating the panel nature of the dataset would be relevant to answering your question.

      You can also similarly save the factor loading matrixes each year in order to explore how qualitatively stable these are over time.

      Comment


      • #4
        Hi Joseph,
        Thank you so much for you assistance, I trully appreciate it!
        When I ran your code, it gets stuck at

        Code:
        quietly set obs `=floor(15000 / 18)'
        I get the following error message:
        Code:
        observation number out of range     Observation number must be between 213,486 and 2,147,483,619.  (Observation numbers are typed without commas.)
        Note that the observation count is indeed 213,486 (I erroneously specified 150.000). However, even when I change the set obs = floor to (213,486), I get the same message. Naturally, when I do run the entire code, the eigenvalue matrix turns out all 0s. Do you know what could be wrong here? Thank you again for your help!

        I'm running STATA 16 on a MBP with 16GB of RAM if it means anything.

        Comment


        • #5
          Originally posted by Joseph Coveney View Post
          Try performing factor analysis separately each year. If the factor structure is stable, then with that many observations it should show up as such in terms of how many factors are warranted. Run the code below, where a stable orthogonal three-factor structure is illustrated in a dataset that has key features that you describe for yours.
          Code:
          version 16.0
          
          clear *
          
          set seed `=strreverse("1526372")'
          
          quietly set obs `=floor(15000 / 18)'
          generate int pid = _n
          quietly expand 18
          bysort pid: generate byte tim = _n
          
          tempname Corr
          matrix define `Corr' = J(3, 3, 0.5) + I(3) * 0.5
          drawnorm v1 v2 v3, double corr(`Corr')
          drawnorm v4 v5 v6, double corr(`Corr')
          drawnorm v7 v8 v9, double corr(`Corr')
          drawnorm v10 v11 v12, double corr(`Corr')
          drop v12
          
          *
          * Begin here
          *
          tempname Eigenvalues
          forvalues tim = 1/18 {
          quietly factor v* if tim == `tim'
          matrix define `Eigenvalues' = (nullmat(`Eigenvalues') \ e(Ev))
          }
          
          contract tim, freq(count)
          svmat double `Eigenvalues', names("Ev")
          format Ev* %03.1f
          
          list tim E*, noobs separator(0)
          
          exit
          If the factor structure isn't stable over time, then I'm not sure that incorporating the panel nature of the dataset would be relevant to answering your question.

          You can also similarly save the factor loading matrixes each year in order to explore how qualitatively stable these are over time.
          Any help with fixing this code? Thanks!

          Comment


          • #6
            Originally posted by John Schawrz View Post
            Any help with fixing this code?
            It doesn't need fixing: the code runs without a hitch as-is.


            .ÿversionÿ16.0

            .ÿ
            .ÿclearÿ*

            .ÿ
            .ÿsetÿseedÿ`=strreverse("1526372")'

            .ÿ
            .ÿquietlyÿsetÿobsÿ`=floor(15000ÿ/ÿ18)'

            .ÿgenerateÿintÿpidÿ=ÿ_n

            .ÿquietlyÿexpandÿ18

            .ÿbysortÿpid:ÿgenerateÿbyteÿtimÿ=ÿ_n

            .ÿ
            .ÿtempnameÿCorr

            .ÿmatrixÿdefineÿ`Corr'ÿ=ÿJ(3,ÿ3,ÿ0.5)ÿ+ÿI(3)ÿ*ÿ0.5

            .ÿdrawnormÿv1ÿv2ÿv3,ÿdoubleÿcorr(`Corr')

            .ÿdrawnormÿv4ÿv5ÿv6,ÿdoubleÿcorr(`Corr')

            .ÿdrawnormÿv7ÿv8ÿv9,ÿdoubleÿcorr(`Corr')

            .ÿdrawnormÿv10ÿv11ÿv12,ÿdoubleÿcorr(`Corr')

            .ÿdropÿv12

            .ÿ
            .ÿ*
            .ÿ*ÿBeginÿhere
            .ÿ*
            .ÿtempnameÿEigenvalues

            .ÿforvaluesÿtimÿ=ÿ1/18ÿ{
            ÿÿ2.ÿÿÿÿÿquietlyÿfactorÿv*ÿifÿtimÿ==ÿ`tim'
            ÿÿ3.ÿÿÿÿÿmatrixÿdefineÿ`Eigenvalues'ÿ=ÿ(nullmat(`Eigenvalues')ÿ\ÿe(Ev))
            ÿÿ4.ÿ}

            .ÿ
            .ÿcontractÿtim,ÿfreq(count)

            .ÿsvmatÿdoubleÿ`Eigenvalues',ÿnames("Ev")

            .ÿformatÿEv*ÿ%03.1f

            .ÿ
            .ÿlistÿtimÿE*,ÿnoobsÿseparator(0)

            ÿÿ+------------------------------------------------------------------------------+
            ÿÿ|ÿtimÿÿÿEv1ÿÿÿEv2ÿÿÿEv3ÿÿÿEv4ÿÿÿÿEv5ÿÿÿÿEv6ÿÿÿÿEv7ÿÿÿÿEv8ÿÿÿÿEv9ÿÿÿEv10ÿÿÿEv11ÿ|
            ÿÿ|------------------------------------------------------------------------------|
            ÿÿ|ÿÿÿ1ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.3ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿÿ2ÿÿÿ1.5ÿÿÿ1.4ÿÿÿ1.1ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿÿ3ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿÿ4ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿÿ5ÿÿÿ1.4ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿÿ6ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿÿ7ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ1.3ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿÿ8ÿÿÿ1.5ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿÿ9ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿ10ÿÿÿ1.5ÿÿÿ1.4ÿÿÿ1.2ÿÿÿ0.6ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿ11ÿÿÿ1.5ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿ12ÿÿÿ1.4ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿ13ÿÿÿ1.5ÿÿÿ1.4ÿÿÿ1.2ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿ14ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿ15ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿ16ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.1ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿ17ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ1.3ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ|ÿÿ18ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
            ÿÿ+------------------------------------------------------------------------------+

            .ÿ
            .ÿexit

            endÿofÿdo-file


            .


            The essential point to be illustrated begins at the Begin Here comment. You don't show any of your data, and so I named the variables as I typically would for such an illustration. For you, modify the code shown beginning with the Begin Here comment by substituting in your variables' names for what I used, and run with it from that point onward.

            Comment


            • #7
              Originally posted by Joseph Coveney View Post
              It doesn't need fixing: the code runs without a hitch as-is.


              .ÿversionÿ16.0

              .ÿ
              .ÿclearÿ*

              .ÿ
              .ÿsetÿseedÿ`=strreverse("1526372")'

              .ÿ
              .ÿquietlyÿsetÿobsÿ`=floor(15000ÿ/ÿ18)'

              .ÿgenerateÿintÿpidÿ=ÿ_n

              .ÿquietlyÿexpandÿ18

              .ÿbysortÿpid:ÿgenerateÿbyteÿtimÿ=ÿ_n

              .ÿ
              .ÿtempnameÿCorr

              .ÿmatrixÿdefineÿ`Corr'ÿ=ÿJ(3,ÿ3,ÿ0.5)ÿ+ÿI(3)ÿ*ÿ0.5

              .ÿdrawnormÿv1ÿv2ÿv3,ÿdoubleÿcorr(`Corr')

              .ÿdrawnormÿv4ÿv5ÿv6,ÿdoubleÿcorr(`Corr')

              .ÿdrawnormÿv7ÿv8ÿv9,ÿdoubleÿcorr(`Corr')

              .ÿdrawnormÿv10ÿv11ÿv12,ÿdoubleÿcorr(`Corr')

              .ÿdropÿv12

              .ÿ
              .ÿ*
              .ÿ*ÿBeginÿhere
              .ÿ*
              .ÿtempnameÿEigenvalues

              .ÿforvaluesÿtimÿ=ÿ1/18ÿ{
              ÿÿ2.ÿÿÿÿÿquietlyÿfactorÿv*ÿifÿtimÿ==ÿ`tim'
              ÿÿ3.ÿÿÿÿÿmatrixÿdefineÿ`Eigenvalues'ÿ=ÿ(nullmat(`Eigenvalues')ÿ\ÿe(Ev))
              ÿÿ4.ÿ}

              .ÿ
              .ÿcontractÿtim,ÿfreq(count)

              .ÿsvmatÿdoubleÿ`Eigenvalues',ÿnames("Ev")

              .ÿformatÿEv*ÿ%03.1f

              .ÿ
              .ÿlistÿtimÿE*,ÿnoobsÿseparator(0)

              ÿÿ+------------------------------------------------------------------------------+
              ÿÿ|ÿtimÿÿÿEv1ÿÿÿEv2ÿÿÿEv3ÿÿÿEv4ÿÿÿÿEv5ÿÿÿÿEv6ÿÿÿÿEv7ÿÿÿÿEv8ÿÿÿÿEv9ÿÿÿEv10ÿÿÿEv11ÿ|
              ÿÿ|------------------------------------------------------------------------------|
              ÿÿ|ÿÿÿ1ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.3ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿÿ2ÿÿÿ1.5ÿÿÿ1.4ÿÿÿ1.1ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿÿ3ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿÿ4ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿÿ5ÿÿÿ1.4ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿÿ6ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿÿ7ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ1.3ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿÿ8ÿÿÿ1.5ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿÿ9ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿ10ÿÿÿ1.5ÿÿÿ1.4ÿÿÿ1.2ÿÿÿ0.6ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿ11ÿÿÿ1.5ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿ12ÿÿÿ1.4ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿ13ÿÿÿ1.5ÿÿÿ1.4ÿÿÿ1.2ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿ14ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿ15ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿ16ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.1ÿÿÿ0.7ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿ17ÿÿÿ1.4ÿÿÿ1.3ÿÿÿ1.3ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ|ÿÿ18ÿÿÿ1.5ÿÿÿ1.3ÿÿÿ1.2ÿÿÿ0.8ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.1ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.2ÿÿÿ-0.3ÿ|
              ÿÿ+------------------------------------------------------------------------------+

              .ÿ
              .ÿexit

              endÿofÿdo-file


              .


              The essential point to be illustrated begins at the Begin Here comment. You don't show any of your data, and so I named the variables as I typically would for such an illustration. For you, modify the code shown beginning with the Begin Here comment by substituting in your variables' names for what I used, and run with it from that point onward.
              Hi Joseph,
              Thank you for your invaluable help!
              This is the code I ran:
              Code:
              clear
              use "C:\Users\maricste\Documents\PhD\Papers\TMT Incentives\compustat for factors.dta"
              set seed `=strreverse("1526372")'
              
              quietly set obs `=floor(15000 / 18)'
              generate int pid = _n
              quietly expand 18
              bysort pid: generate byte tim = _n
              
              tempname Corr
              matrix define `Corr' = J(3, 3, 0.5) + I(3) * 0.5
              drawnorm book1 cf1 ebit1, double corr(`Corr')
              drawnorm ebitda1 pfmargins1 eps1, double corr(`Corr')
              drawnorm earnings1 roa1 roe1, double corr(`Corr')
              drawnorm roic1 sales1 wc1, double corr(`Corr')
              
              *
              * Begin here
              *
              tempname Eigenvalues
              forvalues tim = 1/18 {
                  quietly factor book1 cf1 ebit1 ebitda1 pfmargins1 eps1 earnings1 roa1 roe1 roic1 sales1 wc1 if tim == `tim'
                  matrix define `Eigenvalues' = (nullmat(`Eigenvalues') \ e(Ev))
              }
              
              contract tim, freq(count)
              svmat double `Eigenvalues', names("Ev")
              format Ev* %03.1f
              
              list tim E*, noobs separator(0)
              When I run this, I get this error:

              Code:
              . do "C:\Users\maricste\AppData\Local\Temp\STD1fb0_000000.tmp"
              
              . clear
              
              . use "C:\Users\maricste\Documents\PhD\Papers\TMT Incentives\compustat for factors.dta"
              
              . set seed `=strreverse("1526372")'
              
              .
              . quietly set obs `=floor(15000 / 18)'
              observation number out of range
                  Observation number must be between 213,486 and 2,147,483,619.  (Observation numbers are typed without commas.)
              r(198);
              
              end of do-file
              r(198);

              However, when I run the code without
              Code:
              quietly set obs `=floor(15000 / 18)'
              , the code runs and I get this result:

              Code:
               +-------------------------------------------------------------------------------------+
                | tim   Ev1   Ev2   Ev3   Ev4    Ev5    Ev6    Ev7    Ev8    Ev9   Ev10   Ev11   Ev12 |
                |-------------------------------------------------------------------------------------|
                |   1   1.4   1.4   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |   2   1.3   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |   3   1.4   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |   4   1.3   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |   5   1.4   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |   6   1.4   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |   7   1.4   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |   8   1.3   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |   9   1.3   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |  10   1.3   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |  11   1.4   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |  12   1.4   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |  13   1.4   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |  14   1.4   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |  15   1.4   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |  16   1.4   1.3   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |  17   1.4   1.4   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |  18   1.4   1.4   1.3   1.3   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2   -0.2 |
                |  19     .     .     .     .      .      .      .      .      .      .      .      . |
                |  20     .     .     .     .      .      .      .      .      .      .      .      . |
                |  21     .     .     .     .      .      .      .      .      .      .      .      . |
                |  22     .     .     .     .      .      .      .      .      .      .      .      . |
                |  23     .     .     .     .      .      .      .      .      .      .      .      . |
                |  24     .     .     .     .      .      .      .      .      .      .      .      . |
                |  25     .     .     .     .      .      .      .      .      .      .      .      . |
                |  26     .     .     .     .      .      .      .      .      .      .      .      . |
                |  27     .     .     .     .      .      .      .      .      .      .      .      . |
                |  28     .     .     .     .      .      .      .      .      .      .      .      . |
                |  29     .     .     .     .      .      .      .      .      .      .      .      . |
                |  30     .     .     .     .      .      .      .      .      .      .      .      . |
                |  31     .     .     .     .      .      .      .      .      .      .      .      . |
                |  32     .     .     .     .      .      .      .      .      .      .      .      . |
                |  33     .     .     .     .      .      .      .      .      .      .      .      . |
                |  34     .     .     .     .      .      .      .      .      .      .      .      . |
                |  35     .     .     .     .      .      .      .      .      .      .      .      . |
                |  36     .     .     .     .      .      .      .      .      .      .      .      . |
                |  37     .     .     .     .      .      .      .      .      .      .      .      . |
                |  38     .     .     .     .      .      .      .      .      .      .      .      . |
                |  39     .     .     .     .      .      .      .      .      .      .      .      . |
                |  40     .     .     .     .      .      .      .      .      .      .      .      . |
                |  41     .     .     .     .      .      .      .      .      .      .      .      . |
                |  42     .     .     .     .      .      .      .      .      .      .      .      . |
                |  43     .     .     .     .      .      .      .      .      .      .      .      . |
                |  44     .     .     .     .      .      .      .      .      .      .      .      . |
                |  45     .     .     .     .      .      .      .      .      .      .      .      . |
                |  46     .     .     .     .      .      .      .      .      .      .      .      . |
                |  47     .     .     .     .      .      .      .      .      .      .      .      . |
                |  48     .     .     .     .      .      .      .      .      .      .      .      . |
                |  49     .     .     .     .      .      .      .      .      .      .      .      . |
                |  50     .     .     .     .      .      .      .      .      .      .      .      . |
                |  51     .     .     .     .      .      .      .      .      .      .      .      . |
                |  52     .     .     .     .      .      .      .      .      .      .      .      . |
                |  53     .     .     .     .      .      .      .      .      .      .      .      . |
                |  54     .     .     .     .      .      .      .      .      .      .      .      . |
                |  55     .     .     .     .      .      .      .      .      .      .      .      . |
                |  56     .     .     .     .      .      .      .      .      .      .      .      . |
                |  57     .     .     .     .      .      .      .      .      .      .      .      . |
                |  58     .     .     .     .      .      .      .      .      .      .      .      . |
                |  59     .     .     .     .      .      .      .      .      .      .      .      . |
                |  60     .     .     .     .      .      .      .      .      .      .      .      . |
                |  61     .     .     .     .      .      .      .      .      .      .      .      . |
                |  62     .     .     .     .      .      .      .      .      .      .      .      . |
                |  63     .     .     .     .      .      .      .      .      .      .      .      . |
                |  64     .     .     .     .      .      .      .      .      .      .      .      . |
                |  65     .     .     .     .      .      .      .      .      .      .      .      . |
                |  66     .     .     .     .      .      .      .      .      .      .      .      . |
                |  67     .     .     .     .      .      .      .      .      .      .      .      . |
                |  68     .     .     .     .      .      .      .      .      .      .      .      . |
                |  69     .     .     .     .      .      .      .      .      .      .      .      . |
                |  70     .     .     .     .      .      .      .      .      .      .      .      . |
                |  71     .     .     .     .      .      .      .      .      .      .      .      . |
                |  72     .     .     .     .      .      .      .      .      .      .      .      . |
                |  73     .     .     .     .      .      .      .      .      .      .      .      . |
                |  74     .     .     .     .      .      .      .      .      .      .      .      . |
                |  75     .     .     .     .      .      .      .      .      .      .      .      . |
                |  76     .     .     .     .      .      .      .      .      .      .      .      . |
                |  77     .     .     .     .      .      .      .      .      .      .      .      . |
                |  78     .     .     .     .      .      .      .      .      .      .      .      . |
                |  79     .     .     .     .      .      .      .      .      .      .      .      . |
                |  80     .     .     .     .      .      .      .      .      .      .      .      . |
                |  81     .     .     .     .      .      .      .      .      .      .      .      . |
                |  82     .     .     .     .      .      .      .      .      .      .      .      . |
                |  83     .     .     .     .      .      .      .      .      .      .      .      . |
                |  84     .     .     .     .      .      .      .      .      .      .      .      . |
                |  85     .     .     .     .      .      .      .      .      .      .      .      . |
                |  86     .     .     .     .      .      .      .      .      .      .      .      . |
                |  87     .     .     .     .      .      .      .      .      .      .      .      . |
                |  88     .     .     .     .      .      .      .      .      .      .      .      . |
                |  89     .     .     .     .      .      .      .      .      .      .      .      . |
                |  90     .     .     .     .      .      .      .      .      .      .      .      . |
                |  91     .     .     .     .      .      .      .      .      .      .      .      . |
                |  92     .     .     .     .      .      .      .      .      .      .      .      . |
                |  93     .     .     .     .      .      .      .      .      .      .      .      . |
                |  94     .     .     .     .      .      .      .      .      .      .      .      . |
                |  95     .     .     .     .      .      .      .      .      .      .      .      . |
                |  96     .     .     .     .      .      .      .      .      .      .      .      . |
                |  97     .     .     .     .      .      .      .      .      .      .      .      . |
                |  98     .     .     .     .      .      .      .      .      .      .      .      . |
                |  99     .     .     .     .      .      .      .      .      .      .      .      . |
                | 100     .     .     .     .      .      .      .      .      .      .      .      . |
                |   .     .     .     .     .      .      .      .      .      .      .      .      . |
                +-------------------------------------------------------------------------------------+
              This should imply a relatively stable factor structure and a three factor solution, correct? The only thing left to do would be to identify which variables load on which factor?

              Thank you again for your invaluable assistance!


              .

              Comment


              • #8
                You might want to look into a basic Stata course so as to learn how to use the software. You can find something or online if your institution doesn't offer anything. The user's manuals are a good source, too.

                In the meantime, you can look at the forum's FAQ about how to pose a question, describe your dataset and so on. Maybe there are participants who are familiar with COMPUSTAT and are willing to help you here without having to be informed about the structure of your dataset and the variable name for years.

                Comment


                • #9
                  Joseph Coveney gives excellent advice as always. Meanwhile one strategic error in #7 is clear. Joseph was giving code to fake some data and then use the result. You don't need that code on your own data, which you have and manifestly Joseph doesn't have,

                  Comment


                  • #10
                    OK, thank you both for your help! I will look into figuring out the rest.

                    Comment

                    Working...
                    X