Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Simulation for cluster with unequal size


From   "Raja, Dr. Edwin Amalraj" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Simulation for cluster with unequal size
Date   Wed, 26 Mar 2014 15:46:35 +0000

Dear Statslist,

I am using stata ver 13 MP.  I want to simulate the 'bangladesh' data (webuse Bangladesh).
I found that it has 61 districts with varying women from 2 to 118 in each district.  I want to simulate the same (type of)  data using urban and child.  I want to simulate the data with similar percentage for each of the variable categories.  I have done that.  I do not know how to create unequal records within each district. I have given below my coding to get parameter estimate using xtmelogit.  The parameter estimate from the 'bangadesh' data is  given at  the bottom.

(i)How  to simulate unequal number of women in each district
(ii) is the conversion from 'xb' - logit of linear combination of parameter  to  outcome correct?

Thanks in advance for your suggestion
Regards
Amalraj




clear
clear matrix
set mem 990000
set matsize 750
set more off

webuse bangladesh

sort district
by district: gen n=_n

xtset district n
xtdes
tab n
sort district n
by district: egen noclus=max(n)
tab noclus if n==1

gen child=1 if child1==1
replace child=2 if child2==1
replace child=3 if child3==1
replace child=0 if child==.

tab district
tab child
tab urban


xtmelogit c_use urban child1 child2 child3 || district:,

xi:xtmelogit c_use urban i.child || district:,


******************** simulate data  ************************
  clear
  clear all
set mem 1g
set obs 61 //create observations
gen district=_n //Create ID numbers
*      to generate mbmi category

*      to generate random effect

gen rand = uniform()
gen childc= cond(rand<.274,0, cond(rand<.457,1, cond(rand<.616,2,3))) // generate child : discrete uniform random variables, to have child0 (27.4%), child1(18.3%), child2(15.87%) & chidl3(38.4%)
*xi i.childc, pre(cat_)
gen childc1=1.01*(childc) if childc==1         // *invnorm(uniform())
gen childc2=.647*(childc) if childc==2      // *invnorm(uniform())
gen childc3=1.284*(childc) if childc==3      // *invnorm(uniform())

replace childc1=0 if childc1==.
replace childc2=0 if childc2==.
replace childc3=0 if childc3==.

gen rand1 = uniform()
gen urban= cond(rand1<.71,0,1)     // generate urban

tab childc
tab urban

egen district_id = group(district)
bys district_id: ge tag = _n == 1


gen u_c=rnormal(0, 0.46) if tag
bys district_id : replace u_c = u_c[1]

gen e_ic =  logit( runiform() )

gen xb = -1.47 + childc1 + childc2 + childc3 + u_c+e_ic

gen y = runiform() < invlogit(xb)

tab y









Mixed-effects logistic regression               Number of obs      =      1934
Group variable: district                        Number of groups   =        60

                                                Obs per group: min =         2
                                                               avg =      32.2
                                                               max =       118

Integration points =   7                        Wald chi2(4)       =     99.66
Log likelihood = -1212.6015                     Prob > chi2        =    0.0000

------------------------------------------------------------------------------
       c_use |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       urban |   .7181959   .1188872     6.04   0.000     .4851812    .9512105
      child1 |   1.010093   .1541231     6.55   0.000     .7080171    1.312169
      child2 |   1.147559   .1609166     7.13   0.000     .8321682     1.46295
      child3 |    .942329   .1322325     7.13   0.000     .6831581      1.2015
       _cons |  -1.476145   .1315992   -11.22   0.000    -1.734075   -1.218215
------------------------------------------------------------------------------

------------------------------------------------------------------------------
  Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
-----------------------------+------------------------------------------------
district: Identity           |
                   sd(_cons) |    .458631   .0787261      .3276053    .6420606
------------------------------------------------------------------------------
LR test vs. logistic regression: chibar2(01) =    42.06 Prob>=chibar2 = 0.0000
The University of Aberdeen is a charity registered in Scotland, No SC013683.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index