Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Chi-square test for Categorical Data Analysis


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Chi-square test for Categorical Data Analysis
Date   Thu, 20 Sep 2007 22:09:04 +0100 (BST)

--- Maarten buis <[email protected]> wrote:
> In the example below I simulate the the results if we had the
> continuous data, use -intreg- with log transformed endpoints, and log
> transformed mid-point scaling. All three methods seem to perform ok.

In the example below you see an altarnative simulation in which both
-intreg- and mid-point scaling don't do so well:

*---------------- begin example -------------------
set more off
set seed 12345

sysuse nlsw88, clear
keep collgrad wage
gen lnwage = ln(wage)
reg lnwage collgrad
local pop = _b[collgrad]


capture program drop sim
program sim, rclass
	sysuse nlsw88, clear
	gen ran = uniform()
	sort ran
	keep in 1/1000
	egen wagecat = cut(wage), ///
	at(0, 5, 10, 20, 30, 50)

	gen wagecat2 = wagecat	
	recode wagecat2 ( 0 =  5) ///
      	          ( 5 = 10) ///
     	      	    (10 = 20) ///
                	    (20 = 30) /// 
                	    (30 = 50) 
	gen lncat  = ln(wagecat + .5)
	gen lncat2 = ln(wagecat2)
	intreg lncat lncat2 collgrad
	return scalar xcat = _b[collgrad]

	gen mid = wagecat
	recode mid ( 0 =  3  ) ///
                 ( 5 =  7.5) ///
     	           (10 = 15)   ///
                 (20 = 25)   /// 
                 (30 = 40) 
	gen lnmid = ln(mid)
	reg lnmid collgrad
	return scalar xmid = _b[collgrad]

	gen lnwage = ln(wage)
	reg lnwage collgrad
	return scalar xcont = _b[collgrad]
end
simulate xcat=r(xcat) xmid=r(xmid) xcont=r(xcont) ///
, reps(1000): sim
twoway kdensity xcont ||            ///
       kdensity xcat  ||            ///
       kdensity xmid,               ///
       xline(`pop')                   ///
       xtitle("effect of collgrad") ///
       ytitle("density")            ///   
       legend(order(1 "continuous"  ///
                      "wage"        ///
                    2 "intreg"      ///
                    3 "mid point"   ///
                      "scoring"))       
sum
*--------------- end example ------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      ___________________________________________________________ 
Want ideas for reducing your carbon footprint? Visit Yahoo! For Good  http://uk.promotions.yahoo.com/forgood/environment.html
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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