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]

Re: st: new tsb command


From   "Ng, Edmond" <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   Re: st: new tsb command
Date   Thu, 6 Jun 2013 22:49:22 +0000

Hi Margaret, 

The new user-written command, tsb, works similarly to Stata's own 'bootstrap'. It performs a two-stage bootstrap algorithm on a user supplied function, f(), with a shrinkage correction for possible overestimation due to second-stage sampling . The main difference is that the child function, f(), expected by 'tsb' is a Mata function. I have provided three such functions in the tsb package (package st0288 downloadable from the Stata Journal website) and their syntaxes are included in the accompanying Stata paper (Ng et al 2013 Stata Journal 13(1):pp141-164). 

To apply 'tsb' on the difference between the cluster-level treatment means you will have to write your own child Mata function to calculate this difference. To save you some time, I have provided the syntax for a new child function, meandiff(), for calculating this difference. I assumed your treatments are applied at the cluster-level.  Do test it and check if the results make sense to you before using it for analysis. 

Run the following syntax in Stata to create 'meandiff.mo' and save it into your personal directory. You are likely to have to modify the path for your personal directory (see 2nd line from the bottom). If not sure where this directory is on your computer, type 'sysdir' to find out. 

An example syntax for this new child function would be: 
> tsb cost, stats(&meandiff()) cluster(cluster) strata(int1)

Hope this is useful. 

BW, Edmond 


************ START OF MEANDIFF.DO ************ 
capture mata: mata drop meandiff()
mata: 
real scalar function meandiff(transmorphic matrix data)  
{ 
version 12.1
/* DECLARATIONS */ 
real matrix cost, treat 
real scalar mc_ctl, mc_tmt
/* DATA CHECKING */ 
if (cols(data)!=3){
 _error("Function requires an input data matrix of 3 columns wide.") 
 }
cost=data[,1]
treat=data[,3]
/* DATA CHECKING */ 
/* 1. Stop if treatment var has anything other than 2 levels */ 
if (rows(uniqrows(treat))<2) {
 _error("Treatment variable has <2 unique values.") 
 } else if (rows(uniqrows(treat))>2) {
 _error("Treatment variable has >2 unique values.") 
} 
/* Calculate INB */ 
mc_ctl=mean(select(cost,treat:==uniqrows(treat)[1])) /* mean cost for ctl */ 
mc_tmt=mean(select(cost,treat:==uniqrows(treat)[2])) /* mean cost for tmt */ 
meandiff = mc_tmt-mc_ctl  
return(meandiff) 
}
mata mosave meandiff(), dir("h:\stata\ado\personal") replace 
end
************ END OF MEANDIFF.DO ************ 


*********
Edmond Ng
CPRD, UK 
*********




This email and any files transmitted with it are confidential. If you are not the intended recipient, any reading, printing, storage, disclosure, copying or any other action taken in respect of this email is prohibited and may be unlawful. 

If you are not the intended recipient, please notify the sender immediately by using the reply function and then permanently delete what you have received.Incoming and outgoing email messages are routinely monitored for compliance with the Department of Healths policy on the use of electronic communications. 

For more information on the Department of Healths email policy, click 
http://www.dh.gov.uk/DHTermsAndConditions/fs/en?CONTENT_ID=4110945&chk=x1C3Zw

The original of this email was scanned for viruses by the Government Secure Intranet virus scanning service supplied by Vodafone in partnership with Symantec. (CCTM Certificate Number 2009/09/0052.) On leaving the GSi this email was certified virus free.
Communications via the GSi may be automatically logged, monitored and/or recorded for legal purposes.

*
*   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