Announcement

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

  • How to only keep the regression coefficients of the key treatment variables in my regression output?

    I want to keep only the regression coefficients of the treatment variables in my regression output. How do I achieve this? I have tried quite a few versions of the code below, but in every iteration, the output comes with all the controls and year-fixed effects.


    local dep_vars "Violent_std Property_std Property2_std Murder_std Manslaughter_std Rape_std Robbery_std Assault_std Burglary_std Larceny_std Vehcile_Theft_std Other_Assault_std Arson_std Stolen_Property_std Vandalism_std All_Drug_Abuse_std Embezzlement_std Weapons_std Prostitution_std DUI_std Disorderly_std Fraud_std Forgery_std "

    local treat_vars "Minor13 Minor49 Minor1020 Major13 Major49 Major1020"

    local indep_vars "L1.Total_Crime_std Black_Prop_std Labor_Force_std Unemp_Rate_std Tot_Establishments_std Avg_Monthly_Wage_std"

    local i = 1
    foreach dep_var in `dep_vars' {
    qui xtreg `dep_var' `treat_vars' `indep_vars' i.year, fe vce(cluster fips)
    estimates store HurrReg`i'
    local i = `i' + 1
    }


    esttab HurrReg1, cells(b(star fmt(3)) se(par fmt(2))) ///
    keep (`treat_vars') ///
    stats(N r2 r2_a p, labels("Observations" "R-square" "Adjusted R-square" "Model Significance")) ///
    title("Regression Results")

  • #2
    Cross-posted at https://stackoverflow.com/questions/...-variables-in-

    Comment


    • #3
      Nick,

      The post has been deleted from Stackoverflow
      Last edited by Anupam Ghosh; 09 Jan 2024, 22:41.

      Comment


      • #4
        There is nothing wrong about cross-posting. What we ask is that you tell us about it. https://www.statalist.org/forums/help#crossposting

        Comment


        • #5
          Nick,
          Thanks for letting me know! I greatly appreciate the help that I have been receiving from this forum.

          Comment


          • #6
            As nobody else has offered a solution to your original question, I will jump in and speculate on one. I think the problem lies neither in the code nor in your data, but in the way you are running the code.

            My conjecture is that you are interrupting execution somewhere between where you define local macro treat_vars and your -esttab- command. Perhaps you are running it line by line, or in chunks that separate those key points. If that is what you are going, you need to bear in mind two important general principles in Stata:
            1. Local macros, by the very definition of local, exist only within their defining contexts. The defining context includes any chunk of code that is run as a block by itself. Once you reach the end of that block, the local macro ceases to exist. So if you are interrupting execution between definition and use of a local macro, you will fail because the macro will go out of existence between then. A non-existent macro is always interpreted by Stata as an empty string.
            2. In most Stata contexts where a varlist is expected, if nothing is specified, it is interpreted as meaning all of the variables.
            Applying these principles, if you interrupt execution between defining local macro treat_vars and your -esttab- command, by the time you get to the -esttab- command the contents of local macro treat_vars have disappeared and `treat_vars' is just an empty string. The -keep()- option of -esttab- interprets what you specify as a varlist. Since you have inadvertently specified an empty string, it interprets that as instruction to keep all of the variables, which it then does.

            It is easy enough to prove or disprove my hypothesis. Run the code from beginning to end without any interruption. If I am right, -esttab- will behave as you expected and show only the specified treatment variables.

            Comment

            Working...
            X