Announcement

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

  • Macro

    Good day everyone. I am trying to generate 4 ols regression models. I have created globals for my control variables and for my outcome variables. Below is my code. I get an error message - unexpected end of the file. How do I resolve this?

    global VAR = "white_nh black_nh other_nh hispanic age_u20 age2026 age2730 age3135 age4145 age4650 age5155 age5660 age6164 age65pl lessshs hsged hsbelow socol college under25k income25_50k income75_100k income100pl childless child_1 child_2 child_3 i.gendernew married under138fpl btwn138400 over400fpl"

    global outcome = "eshi pvtng medicaid uninsured"

    eststo clear

    foreach y in $outcome {
    foreach g in $VAR {
    eststo: reg `y' i.notworking_cvd##i.expansion i.notworking_non##i.expansion $VAR

    quietly estadd local NonExpMean = round(r(mean), 0.1) if workstatus==0
    quietly estadd local ExpMean = round(r(mean), 0.1) if workstatus==0

    }

  • #2
    I don't know what eststo and estadd are, but you're mssing a close brace for one of your foreach loops. That would give rise to the error message that you got.

    It seems as if it's a specification search. Is that what these two commands are for?

    Comment


    • #3
      You are asking there for 32 x 4 = 128 models not 4. I guess you want a single loop

      Code:
      foreach y in $outcome {
      
      eststo: reg `y' i.notworking_cvd##i.expansion i.notworking_non##i.expansion $VAR
      
      quietly estadd local NonExpMean = round(r(mean), 0.1) if workstatus==0
      quietly estadd local ExpMean = round(r(mean), 0.1) if workstatus==0
      
      }
      That is, I guess that you don't want to loop over your control variables.

      Joseph Coveney has a good point: eststo and estadd are community-contributed commands, and you're asked to explain where they come from -- in this case estout from SSC. See FAQ Advice #12. They are great commands -- which I never use because I never need the ritual display of elaborate results tables. So, I can't comment on whether your syntax will work otherwise.

      But as explained in Section 4 of https://journals.sagepub.com/doi/pdf...867X1801800311 round() with second argument of 0.1 is a poor way to ask for a display format. If you want %2.1f as a display format, just ask for it.

      A fact that will sometimes bite you is that Stata can't hold most multiples of 0.1 exactly -- because at machine level it works in binary. Most of the time Stata does its level best to protect you from this, but it is discernible.

      Code:
      . di %23.18f  round(1/10, 0.1)
         0.100000000000000006
      If you want a deeper understanding of why it seems that Stata can't do arithmetic,

      Code:
      search precision
      will show some resources.

      Comment


      • #4
        Thanks so much Joseph and Nick. The code work on including the missing close brace.The estadd command can be found in http://repec.org/bocode/e/estout/estadd.html.
        I want to add descriptive statistics of my regressors into my table. Thanks, Nick. I will look the article you shared on rounding.

        Comment

        Working...
        X