Announcement

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

  • Stata correct identification of coefficients after regression (loop)

    Dear all,

    I am currently working on a dataset (with information on time allocated from people to many different activities, collected with 3 surveys over 3 years) where I have to run many regressions. The explanatory var are always the 3 years (year_1, year_2, year_3) while the dependent is changing (every regression has a different activity as dependent var), Moreover, I am also running all these different regression on different subsamples of the dataset (i.e., only male aged in same range). Finally, after the estimation, I want to perform a linear hypothesis test on the difference between the estimated values of the coefficients of the first and last year.
    I am using a loop I found.
    In this loop I refer to some local I create in this same do-file, which are:1) "variables", containing the activities (in the example belolw, it actually contains only one activity); 2)"surveys" which contains year_1, year_2 and year_3; 3) "sample" (which I rewrite here before the loop cause it is a local defined different from what I am used to, because it is not selecting a group of variables but a group of observations, in this case only males in the second age class).


    local sample = "if sex==1 & age_2"
    local i = 1
    foreach var of varlist `variables' {
    quietly reg `var' `survey' [aw=weight_tot] `sample', noc
    local addstat = _b[year_3]-_b[year_1]
    lincom _b[year_3]-_b[year_1]
    local coef=r(estimate)
    local se=r(se)
    local t=`coef'/`se'
    local pval=2*ttail(e(df_r),abs(`t'))
    if `i'==2 {
    outreg2 `survey' using UnpaidWork_3554_Male01-03.xls, ctitle(`var')bdec(2) se nor2 noaster addstat("Change01-03",`addstat', "P Value01-03",`pval') append
    }
    if `i'==1 {
    outreg2 `survey' using UnpaidWork_3554_Male01-03.xls, title(35-54 Male) ctitle(`var') bdec(2) se nor2 noaster addstat("Change01-03",`addstat', "P Value01-03",`pval') replace
    local i=2
    }
    }

    Since I found this loop, I would like to be sure about what it is doing when saying "local coef=r(estimate)". It is taking the estimated difference of my hipothesis test identified by " lincom _b[survey_03]-_b[survey_01]", isn't it?

    Thank you a lot in advance!!
    Last edited by Claire Essy; 05 May 2019, 11:04.

  • #2
    I would like to be sure about what it is doing when saying "local coef=r(estimate)". It is taking the estimated difference of my hipothesis test identified by " lincom _b[survey_03]-_b[survey_01]", isn't it?
    Yes.

    By the way, it appears that local addstat and local coef will always contain the same thing, so you don't really need both. I would simplify the code by eliminating the command creating local addstat, and replacing all subsequent references to `addstat' by `coef'.

    In the future, when posting Stata code, please place it between code delimiters so that indentation is preserved and readability enhanced. If you are not familiar with code delimiters, please read Forum FAQ #12 for instructions.

    Comment


    • #3
      Thank you for your answer Clyde, and thank you also for your advise on correct posting of stata code!

      Comment

      Working...
      X