Announcement

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

  • "variable ccode not found" when doing a xtreg

    Hello everybody!

    I am quite new to Stata, and have much to learn. However, I am trying to perform a regression on a data set with data taken from CEPII. I have a panel data with many countries and their trade partner as observation, and the variables I have included are exports, imports, distance, population, GDP, colonial history, common languages, contiguity and the existence of free trade agreement.

    However, when trying to perform the command xtreg logXPTOT lgdp_o lgdp_d lpop_o lpop_d logDist Comlang Contig Evercol EU Zaf_fta, fe, I get the error message: ""variable ccode not found". I have installed xtpattern. Another question, how do I generate the variable fe?

    I would be very grateful if someone had a solution to my problem.

    Thank you


  • #2
    What does

    Code:
    xtset
    show you?

    Comment


    • #3
      Originally posted by Nick Cox View Post
      What does

      Code:
      xtset
      show you?
      When typing the command xtset, I do also get the the error message "variable ccode not found". So I am figuring if I need to install something as it appears that I missing something in my program?

      Comment


      • #4
        Olav:
        have you already checked that -ccode- does not have any leading and/or trailing blanks?
        Kind regards,
        Carlo
        (StataNow 18.5)

        Comment


        • #5
          It's not necessarily a question of installing anything. To run xtreg you need to xtset your data. My guess is that ccode was given previously as a panel identifier but that it has been removed from the data or renamed.

          #4 Carlo Lazzaro If ccode is a string variable then it couldn't be a panel identifier for xtset. If it exists at all, I think the error message would be different.

          Comment


          • #6
            Nick:
            yes, you're right.
            I thought that -ccode- was a numeric variable imported in Stata from some external source with some formatting issue.
            As an aside, if Olav goes -xtreg,fe- Stata will calculate the -fe- for him:
            Code:
            . xtreg ln_wage age, fe
            
            Fixed-effects (within) regression               Number of obs     =     28,510
            Group variable: idcode                          Number of groups  =      4,710
            
            R-sq:                                           Obs per group:
                 within  = 0.1026                                         min =          1
                 between = 0.0877                                         avg =        6.1
                 overall = 0.0774                                         max =         15
            
                                                            F(1,23799)        =    2720.20
            corr(u_i, Xb)  = 0.0314                         Prob > F          =     0.0000
            
            ------------------------------------------------------------------------------
                 ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                     age |   .0181349   .0003477    52.16   0.000     .0174534    .0188164
                   _cons |   1.148214   .0102579   111.93   0.000     1.128107     1.16832
            -------------+----------------------------------------------------------------
                 sigma_u |  .40635023
                 sigma_e |  .30349389
                     rho |  .64192015   (fraction of variance due to u_i)
            ------------------------------------------------------------------------------
            F test that all u_i=0: F(4709, 23799) = 8.81                 Prob > F = 0.0000
            
            . predict fixed_effect, u
            (24 missing values generated)
            
            .
            Kind regards,
            Carlo
            (StataNow 18.5)

            Comment


            • #7
              Originally posted by Nick Cox View Post
              It's not necessarily a question of installing anything. To run xtreg you need to xtset your data. My guess is that ccode was given previously as a panel identifier but that it has been removed from the data or renamed.

              #4 Carlo Lazzaro If ccode is a string variable then it couldn't be a panel identifier for xtset. If it exists at all, I think the error message would be different.
              Thank you for you reply. The data set that I am using is based on two different data sets that I merged together. I tried performing the xtset on the original data set, and also here, the error message regarding ccode appeared. I tried to create a new unique identifier to the data set, but it did not make any difference. Do you possible know if it is possible to solve this by trying to add a new panel identifier, or do I need to go back to the original data set?

              best regards
              Olav

              Comment


              • #8
                Originally posted by Carlo Lazzaro View Post
                Nick:
                yes, you're right.
                I thought that -ccode- was a numeric variable imported in Stata from some external source with some formatting issue.
                As an aside, if Olav goes -xtreg,fe- Stata will calculate the -fe- for him:
                Code:
                . xtreg ln_wage age, fe
                
                Fixed-effects (within) regression Number of obs = 28,510
                Group variable: idcode Number of groups = 4,710
                
                R-sq: Obs per group:
                within = 0.1026 min = 1
                between = 0.0877 avg = 6.1
                overall = 0.0774 max = 15
                
                F(1,23799) = 2720.20
                corr(u_i, Xb) = 0.0314 Prob > F = 0.0000
                
                ------------------------------------------------------------------------------
                ln_wage | Coef. Std. Err. t P>|t| [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                age | .0181349 .0003477 52.16 0.000 .0174534 .0188164
                _cons | 1.148214 .0102579 111.93 0.000 1.128107 1.16832
                -------------+----------------------------------------------------------------
                sigma_u | .40635023
                sigma_e | .30349389
                rho | .64192015 (fraction of variance due to u_i)
                ------------------------------------------------------------------------------
                F test that all u_i=0: F(4709, 23799) = 8.81 Prob > F = 0.0000
                
                . predict fixed_effect, u
                (24 missing values generated)
                
                .
                Many thanks for your message.

                I tried performing the xtreg logXPTOT Distw, fe on my variables, but also here, I received the error message:

                xtreg logXPTOT Distw, fe
                variable ccode not found
                r(111);

                I really don't know how to solve this, because ccode appears to stop all sorts of calculations.

                Thank you, and best regards

                Comment


                • #9
                  Olav:
                  type:
                  Code:
                  xtset, clear
                  and then

                  Code:
                  xtset paneid timevar
                  Kind regards,
                  Carlo
                  (StataNow 18.5)

                  Comment


                  • #10
                    Originally posted by Carlo Lazzaro View Post
                    Olav:
                    type:
                    Code:
                    xtset, clear
                    and then

                    Code:
                    xtset paneid timevar
                    Thank you once again!

                    Initially it worked, but as my data set included many countries, each separated from each other by years, it did not work as intended. Is there any ways to create a common value for years making it possible to perform your command?

                    This is what I got:

                    xtset ID year
                    repeated time values within panel
                    r(451);

                    thank you

                    Comment


                    • #11
                      Olav:
                      your last reported issue is far easier to manage than the previous one.
                      If you do not plan to use time series related commands, such as lags and leads, in your -xtreg,fe-, you can simply -xtset- your dataset with -panelid- only:
                      Code:
                      xtset panelid
                      Kind regards,
                      Carlo
                      (StataNow 18.5)

                      Comment


                      • #12
                        Originally posted by Carlo Lazzaro View Post
                        Olav:
                        your last reported issue is far easier to manage than the previous one.
                        If you do not plan to use time series related commands, such as lags and leads, in your -xtreg,fe-, you can simply -xtset- your dataset with -panelid- only:
                        Code:
                        xtset panelid
                        Thank you very much, now everything worked as it should. Couldn't have done it without your help.

                        Comment

                        Working...
                        X