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: how to do fixed effects with weights? (problem using svy: with xtreg, fe)


From   Steve Samuels <[email protected]>
To   [email protected]
Subject   Re: st: how to do fixed effects with weights? (problem using svy: with xtreg, fe)
Date   Wed, 14 Apr 2010 13:40:38 -0400

 You will have to substitute -xtreg- and its options in two places, as
 indicated by the comment boxes.    This will have to do until somebody
 writes a program wrapper for -xtreg-; that is beyond my skills, I'm
 afraid.

 The first command should run with [pweight=c1_5fp00] weight variable.
 In the second, the  option should be:  [pw= c1_5fp `j']

 Steve

 **************************CODE BEGINS**************************
 capture log close
 set more off
 log using t06, replace text

 set linesize 100
 use http://www.stata-press.com/data/r11/nhanes2jknife, clear
 ***************************************************************
 * Set up options in next four lines
 ***************************************************************
 local  nreps 62   //jackknife replicates
 local  dof   31    //degrees of freedom
 local  multiplier 0.5
 local  yvar  "weight"            //outcome
 local  xvars "height hgb"      //predictor list

 ***************************************************************
 * Insert your command after this, with options
 ***************************************************************
 regress `yvar' `xvars' [pw=finalwgt]

 tempfile t1
 save `t1'
 clear
 set obs 1
 matrix b= e(b)
 matrix colnames  b = `xvars'  cons
 svmat b, names(col)
 xpose, clear varname
 rename v1 coeff
 rename _varname vname
 order vname coeff

 tempfile t2
 save `t2'

 use `t1', clear
 tempname memhold
 local xvars=  "`xvars'"
 local zvars = "`xvars'" + " _cons"

 postfile `memhold' `zvars' using results, replace
 local k=  wordcount("`zvars'")

 local postv = ""
 forvalues j= 1/`k'{
 local postv = "`postv'" + " (_b["+word("`zvars'",`j')+"])"
 }

 quietly forvalues j  = 1/`nreps'{
 ***************************************************************
 ** Second version of command
 ***************************************************************
 reg `yvar' `xvars' [pw= jkw_`j']
 post `memhold'  `postv'
 }
 postclose `memhold'

 use results, clear
 rename _cons cons
 ds
 foreach v in `r(varlist)'{
   sum `v', meanonly
   gen double m_`v'=r(mean)   //mean
   gen double  t`v' = `multiplier'*(`v' - m_`v')^2   //
   egen double se_`v' = total(t`v')
   replace se_`v' =sqrt(se_`v')
   drop t`v'
   }
 keep in 1
 drop `xvars' cons
 tempfile t3
 save `t3'
 keep m_*
 renpfix m_

 order `xvars' cons
 xpose , varname clear
 rename v1 jkcoeff
 order _varname
 rename _varname vname
 tempfile t4
 save `t4'

 use `t3',clear
 keep se_*
 renpfix se_
 order `xvars' cons
 xpose, varname clear
 order _varname
 rename v1 stderr
 rename _varname vname
 gen rnum=_n
 mmerge vname using `t4'

 drop _merge
 mmerge vname using `t2'
 drop _merge
 sort rnum
 drop rnum
 order vname coeff jkcoeff stderr
 gen bound = invttail(`dof',0.025)*stderr
 di `bound'
 gen t= coeff/stderr
 gen pvalue = 2*ttail(`dof',abs(t))
 gen llim_95 = coeff-bound
 gen ulim_95 = coeff +bound
 format pvalue %5.3f

 list vname coeff stderr t pvalue llim_95 ulim_95
 save results2, replace
 log close
 ***************************CODE ENDS***************************



 On Wed, Apr 14, 2010 at 9:44 AM, Aleksandra Holod <[email protected]> wrote:
> Thank you, Steve and Stas, for your responses to my statalist post.
> Per your inquiry, my name is Aleksandra Holod and I am doctoral
> student at Columbia.  I had to send my post from an unconfigured
> university e-mail account called "ah2574" because I subscribed with
> that address.
>
> On Mon, Apr 12, 2010 at 11:38 AM, Steve Samuels <[email protected]> wrote:
>> "ah2574"
>>>>
>>> On Sun, Apr 11, 2010 at 2:43 PM,  <[email protected]> wrote:
>>>> I am analyzing longitudinal data on children's educational achievement using
>>>> the "xtreg, fe" command.  My challenge is that I can't seem to weight the
>>>> data with the "svy:" command when running a fixed effects model.  I am
>>>> working with Early Childhood Longitudinal Study-Kindergarten Cohort data
>>>> from the National Center for Education Statistics; the study employed a
>>>> multistage probability sample design (with three stages).
>>>>
>>>> As advised by a technical consultant at the American Institutes for
>>>> Reserach, I am currently "survey setting" the data using replicate weights
>>>> as follows:
>>>> svyset [pweight=c1_5fp0], jkrweight( c1_5fp1-c1_5fp90, multiplier(1))
>>>>
>>>> I then attempted to run the fixed effects model with this syntax:
>>>> svy jacknife: xtreg ztime incneed married momwork numchild, i(childid2) fe
>>>>
>>>> I receive the following error message:
>>>> xtreg is not supported by svy with vce(jackknife)
>>
>


 --
 Steven Samuels
 [email protected]
 18 Cantine's Island
 Saugerties NY 12477
 USA
 Voice: 845-246-0774
 Fax:    206-202-4783
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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