Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Can -outreg- show the coefficient in (eform-1)*100


From   "Danielle H. Ferry" <[email protected]>
To   StataList <[email protected]>
Subject   Re: st: Can -outreg- show the coefficient in (eform-1)*100
Date   Tue, 01 Jul 2003 08:24:43 -0400

Renzo,
I am attaching one of my do-files where I run several regressions + lincoms
and then use -parmest- to produce a table that is similar in appearance to
what outreg would have produced. It is not pretty and should really have
most of the commands hidden in an ado-file, but I am still learning to write
ado-files and don't have the time right now. But, perhaps it will be helpful
to you. At the v. least, it may help illuminate some of the capabilities and
flexibility of the -parmest- package, for which I am eternally grateful to
Roger Newson. 
-Danielle

On 6/30/03 11:07 AM, "Renzo Comolli" <[email protected]> wrote:

> Dear Statalist,
> 
> I am using -outreg- version 3.0.6  27nov00
> Intercooled Stata 8.0 for Windows
> 
> I need to show the regression coefficients (which Stata stores in e(b)) in
> the following format
> (exp(e(b))-1)*100
> is it possible to do so with -outreg-? Maybe writing a line before -outreg-?
> I tried to write the following lines, but the execution breaks at the second
> line:
> regress ln_wage women other_regressors
> replace e(b)=(exp(e(b)-1)*100)
> outreg using myregression.txt, replace se
> 
> I imagine that this problem has been tackled many times before, in fact, in
> the example here, the transformation (exp(b)-1)*100 has the interpretation
> "women's wages are % lower than men's".
> 
> I know -outreg, eform- shows the regression coeffcients b in the form exp(b)
> and adjusts the standard errors correspondently, but that's one step short
> of what I need.
> 
> I looked also at -reformat- but it does not do it either. I can't use
> -mktab- for unrelated reasons.
> I haven't understood how to use -parmby-, so I would avoid if possible.
> 
> Thank you very much.
> 
> Sincerely,
> Renzo Comolli

Attachment: reg17b_cap_teen.do
Description: application/applefile

/* *********************************************************************************************
FILE: reg17b_cap_teen.do
PATH: D:\dferry\abReg\anyCap\regs
ORIGINAL DATE: 06.30.03
DATE MODIFIED: 06.30.03
DESCRIPTION: Outcome = ln births. Age = 15-19. 24 states + NYC. This is repeated 
2x for each race (white/black).
AUTHOR: D. Ferry
VERSION: 8.0
********************************************************************************************* */

# delimit;
drop _all;
set more off;
set matsize 800;

local REG_NUM = 3; /* SET # OF REGS HERE */
local LC_NUM = 2; /* SET # LINCOMS HERE */
local VAR_NUM = 14; /* SET # RESULTS TO BE LISTED IN TABLE */

forval i = 1(1)2 {; /* RACE */

	/* WORKING DATASET; UNIVERSE = TEENS, 24 STATES + NYC */
	use :FIRELITE:dferry:abReg:gruntwork:abReg_teens.dta, clear; 

	/* CREATE ANALYSIS VARS */
	qui do reg1_cap_teen_var;
	qui do reg3_cap_teen_var;
	qui do reg13_cap_var;
	qui do reg17_cap_teen_var;
	
	tempfile reg1 reg2 reg3 lin;
	
	di "";
	di "************************************** RACE=`i' **************************************";
	
	di "";	
	di "***** (REG 1) *****";
	
	_estimates drop _all;
	
	/* REGRESSION */
	xi: reg brthLn i.reform ueRate_cur ueRate_lag1 maxAfdc i.state popnLn [aw=pregTot] 
		if race==`i' & pregTot>=30 & noparity==1, robust cluster(state);

	parmest, label format(estimate stderr p %8.3f) saving(`reg1', replace) idnum(1) 
		escal(N r2);

	di "";	
	di "***** (REG 2) *****";

	_estimates drop _all;
	
	/* REGRESSION */
	xi: reg brthLn i.reform i.parity i.parXreform ueRate_cur ueRate_lag1 maxAfdc i.state popnLn 
		parXpopnLn [aw=pregTot] if race==`i' & pregTot>=30, robust cluster(state);

	parmest, label format(estimate stderr p %8.3f) saving(`reg2', replace) idnum(2) 
		escal(N r2);

	di "";	
	di "***** (REG 3) *****";

	_estimates drop _all;
	
	/* REGRESSION */
	xi: reg brthLn i.reform i.parity i.anyCap i.parXreform i.parXanyCap i.reformXanyCap
		i.parXreformXanyCap ueRate_cur ueRate_lag1 maxAfdc i.state popnLn parXpopnLn [aw=pregTot] 
		if race==`i' & pregTot>=30, robust cluster(state);

	parmest, label format(estimate stderr p %8.3f) saving(`reg3', replace) idnum(3) 
		escal(N r2);

	/* LINCOM 1 (DD CAP) */
	lincomest _IparXrefor_1 + _IparXrefora1, hold(oldest1);
	parmest, label format(estimate stderr p %8.3f) saving(`lin'3_1, replace) idnum(3);
	_estimates unhold oldest1;
	
	/* LINCOM 2 (DD PARITY=1 ACROSS STATES) */
	lincomest _IreformXan_1 + _IparXrefora1;
	parmest, label format(estimate stderr p %8.3f) saving(`lin'3_2, replace) idnum(3);
	
	di "**************************************************************************************";	
	
	/* LABEL LINCOM DATA FILES */
	forval t = 1(1)`LC_NUM' {; /* lincom # */
	
		use `lin'3_`t', clear;
		replace label = "Lincom `t'";
		save `lin'3_`t', replace;

	};
	
	/* CONCATENATE REGRESSION & LINCOM RESULTS */
	dsconcat `reg1'
		`reg2'
		`reg3' `lin'3_1 `lin'3_2;
		
	/* RENAME VARIABLES */
	rename es_1 N_;
	rename es_2 R2_;
	rename estimate coeff;
	rename stderr se;

	/* CONVERT NUMERICAL TO STRING */
	tostring N_, f(%9.0f);
	tostring coeff se R2_, f(%9.3f);

	replace label = parm if label=="";

	/* ADD ASTERISKS TO SEs FOR SIGNIFICANCE */
	replace se = "[" + se + "]";
	replace se = se + "*" if p<=0.05;
	replace se = se + "*" if p<=0.01;

	drop if coeff=="0.000" & se=="[0.000]" & p==.; /* THESE WOULD BE VARS 
	WHICH ARE DROPPED FROM THE REG */

	keep idnum parm label coeff se N R2;

	save reg17b_cap_teen_raw_r`i', replace;

	di "*************************************************************************************";	
	
	use reg17b_cap_teen_raw_r`i', clear;
	
	keep if 
		parm == "_Ireform_1" | 
		parm == "_Iparity_1" |
		parm == "_IanyCap_1" |
		parm == "_IparXrefor_1" |  
		parm == "_IparXanyCa_1" | 
		parm == "_IreformXan_1" |
		parm == "_IparXrefora1" |
		parm == "ueRate_cur" |
		parm == "ueRate_lag1" |
		parm == "maxAfdc" |
		parm == "popnLn" | 
		parm == "parXpopnLn" | 
		parm == "(1)";
	
	drop parm;

	reshape wide coeff se N R2, i(label) j(idnum);

	capture drop order;
	ge order = 1 if label=="reform==1";
	replace order = 2 if label=="parity==1";	
	replace order = 3 if label=="anyCap==1";
	replace order = 4 if label=="parXreform==1";
	replace order = 5 if label=="parXanyCap==1";
	replace order = 6 if label=="reformXanyCap==1";
	replace order = 7 if label=="parXreformXanyCap==1";
	replace order = 8 if label=="Current unemployment rate";
	replace order = 9 if label=="1-yr lagged unemployment rate";
	replace order = 10 if label=="maxAfdc";
	replace order = 11 if label=="Ln of population";
	replace order = 12 if label=="(parity==1)*popnLn";
	replace order = 13 if label=="Lincom 1";
	replace order = 14 if label=="Lincom 2";
		
	/* PUT SEs UNDERNEATH COEFFICIENTS FOR EACH VARIABLE */
	bygap label, gap(gap);
	sort label gap;
	forval j = 1(1)`REG_NUM' {;
		by label: replace coeff`j' = se`j'[1] if _n==2;
	};

	bys label: replace order = order[1] if order==.;

	/* PUT N ON BOTTOM */ 
	capture drop bottomrow;
	bygap, gap(bottomrow);
	forval j = 1(1)`REG_NUM' {;
	gsort bottomrow -N_`j';
	replace coeff`j' = N_`j'[1] in l;
	};

	replace label = "N" if bottomrow==1;
	replace order = `VAR_NUM' + 1 if bottomrow==1;
	
	sort order gap;

	/* PUT R2 ON BOTTOM */ 
	capture drop bottomrow;
	bygap, gap(bottomrow);
	forval j = 1(1)`REG_NUM' {;
	gsort bottomro -R2_`j';
	replace coeff`j' = R2_`j'[1] in l;
	};

	replace label = "R2" if bottomrow==1;
	replace order = `VAR_NUM' + 2 if bottomrow==1;
	sort order gap;

	drop se* N_* R2_*;

	/* ADD 2 ROWS TO TOP */
	capture drop row2 row3;
	bygap, gap(row2);
	bygap, gap(row3);
	replace order = -2 if row2==1;
	replace order = -1 if row3==1;
	
	/* RENAME COLUMNS; LABEL ROW 2 */
	forval c = 1(1)`REG_NUM' {;
		rename coeff`c' reg`c';
		replace reg`c' = "[`c']" if row2==1;
	};
	
	/* ADD TITLE */
	capture drop row1;
	bygap, gap(row1);
	replace label = "Outcome = ln births. Age = 15-19. 24 states + NYC; Race = `i'" 
		if row1==1;
	replace order = -3 if row1==1;
	drop row1;
	
	/* ADD NOTES AT BOTTOM */
	capture drop bottomrow;
	bygap, gap(bottomrow);
	sort bottomrow;
	replace label = "Robust standard errors in brackets" if bottomrow==1;
	replace order = `VAR_NUM' + 3 if bottomrow==1;

	capture drop bottomrow;
	bygap, gap(bottomrow);
	sort bottomrow;
	replace label = "* Significant at 5%; ** Significant at 1%" if bottomrow==1;
	replace order = `VAR_NUM' + 4 if bottomrow==1;
	
	capture drop bottomrow;
	bygap, gap(bottomrow);
	sort bottomrow;
	replace order = `VAR_NUM' + 5 if bottomrow==1;
			
	capture drop bottomrow;
	bygap, gap(bottomrow);
	sort bottomrow;
	replace label = "Coeffs not shown for state dummies" if bottomrow==1;
	replace order = `VAR_NUM' + 6 if bottomrow==1;

	capture drop bottomrow;
	bygap, gap(bottomrow);
	sort bottomrow;
	replace label = "All regs exclude cells w/ pregTot<30" if bottomrow==1;
	replace order = `VAR_NUM' + 7 if bottomrow==1;
		
	capture drop bottomrow;
	bygap, gap(bottomrow);
	sort bottomrow;
	replace order = `VAR_NUM' + 9 if bottomrow==1;
	
	capture drop bottomrow;
	bygap, gap(bottomrow);
	sort bottomrow;
	replace label = "Run at $S_TIME, $S_DATE, Using data from $S_FN" if bottomrow==1;
	replace order = `VAR_NUM' + 10 if bottomrow==1;
	
	sort order gap;
	
	/* CHANGE SELECTED COEFF LABELS */
	replace label = "" if gap==1;
	replace label = "DD-cap" if label=="Lincom 1";
	replace label = "DD-parity=1 across states" if label=="Lincom 2";
	
	drop order gap row* bottomrow;
	
	/* SAVE TO DELIMITED TEXT FILE */
	listtex * using reg17b_cap_teen_r`i'.txt, delimiter($) replace;
	
};



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index