Announcement

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

  • no observations error for regressing two IVs that are mutually exclusive

    Dear Statalist,

    I have a dataset with European and non-European countries. I define "europe" as:
    Code:
    gen europe=1 if Countrycode=="AT"|Countrycode=="BG"|Countrycode=="CH"
    replace europe=0 if europe==.
    and "non-europe" as
    Code:
    gen noneurope=1 if Countrycode=="AU"|Countrycode=="BR"|Countrycode=="CN"
    replace noneurope=0 if noneurope==.
    The definition here europe and non-europe are mutually exclusive, there is no overlap or a third category.

    Then I generate an investment score, "score", which is the aggregate score of all investors in the same country:
    Code:
    bysort id year :egen score_europe = total(score) if europe==1
    bysort id year :egen score_noneurope = total(score) if noneurope==1
    and I want to regress both score_europe and score_noneurope in the same regression with AEM as the DV and some control variables:
    Code:
    reg AEM score_europe score_noneurope ROA MB growth leverage i.industry i.year i.country_id ,cl(id)
    And Stata tells me there is no observation. I kind of understand why there is no observation as the two IVs have no overlap. But if I want to regress score_europe score_noneurope in the same regression, what should I do to achieve this?

    Thanks!
    Last edited by Flora Yin; 07 Nov 2021, 07:02.

  • #2
    Flora:
    the issue seems to rest on missing values in both -score_europe- and -score_noneurope- predictors, the sum of which actually listwise deletes all the observations.
    Just to give you an idea, look at the following toy-example:
    Code:
    use "C:\Program Files\Stata16\ado\base\a\auto.dta"
    . g new_domestic=1 if foreign==0
    (22 missing values generated)
    
    . g new_foreign=1 if foreign==1
    (52 missing values generated)
    
    . regress price i.new_domestic i.new_foreign
    no observations
    r(2000);
    To work this issue around, you have to create an unique -investment_score- (say; 0=European countries; 1=Non-european countries) and use -label- to detail them.
    Frankly, I would have used the very same approach for classifying European and non-European countries.
    Last edited by Carlo Lazzaro; 07 Nov 2021, 07:29.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Flora, the code for generating score_europe makes non-European countries have missing values for this variable, while European countries have missing values in score_noneurope. As European and non-European countries are mutually exclusive, no observation would have non-missing values in both scores. The key is to define the values of score_europe and score_noneurope for non-European and European countries, respectively.

      Comment


      • #4
        Just followed Fei to enjoy the very same party!
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Brilliant! Thanks a lot Carlo and Fei!

          Comment

          Working...
          X