Announcement

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

  • For each for multiple regressions

    Hi, I want to run a regression for each of the 19 "localidades" located in the variable COD_LOCALIDAD.


    foreach localidad in COD_LOCALIDAD {

    reg ln_PERCAPITA ethnici1 edumo2 edumo3 edufa2 edufa3 female birthreg2 birthreg3 [iw=FEX_C] if FG==1 & COD_LOCALIDAD == `localidad'
    est sto ols_`localidad'

    }


    The problem with that line of code is that I am only getting one regression, instead of 19. ¿ What am I missing?

  • #2
    I'd perhaps do this:

    Code:
    levelsof COD_LOCALIDAD, local(localidad)
    foreach x in `localidad'{
    reg ln_PERCAPITA ethnici1 edumo2 edumo3 edufa2 edufa3 female birthreg2 birthreg3 [iw=FEX_C] if FG==1 & COD_LOCALIDAD == `x'
    est sto ols_`x'
    }

    Comment


    • #3
      Silvana:
      depending on what you're after, another option can be:
      Code:
      statsby, (COD_LOCALIDAD): reg ln_PERCAPITA ethnici1 edumo2 edumo3 edufa2 edufa3 female birthreg2 birthreg3 [iw=FEX_C] if FG==1
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment

      Working...
      X