Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Right Censored ordered probit with Stata 11


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Right Censored ordered probit with Stata 11
Date   Mon, 26 Sep 2011 08:32:00 +0100

No. The rest of what he said.

But even apart from that, we can't see your input code and dataset.
Remote debugging is going to be very very difficult if you don't work
with code and data (e.g. simulated data, some set you can -webuse- or
-sysuse-) that we can see, not that it will be easy otherwise.

Nick

On Mon, Sep 26, 2011 at 8:25 AM, Urmi Bhattacharya <ub3@indiana.edu> wrote:
> Hi Nick,
>
> Did you mean the one about lines not being properly structured?
>
> Thanks
>
> Urmi
>
>
> On Mon, Sep 26, 2011 at 12:44 PM, Nick Cox <njcoxstata@gmail.com> wrote:
>> As far as I can tell you are ignoring Austin's advice in his last email.
>>
>> I can't illuminate what is happening with your code and data.
>>
>> Nick
>>
>> On Mon, Sep 26, 2011 at 3:50 AM, Urmi Bhattacharya <ub3@indiana.edu> wrote:
>>> Hi Nick and Austin,
>>>
>>> Thank you so much for your suggestions. I put the
>>> set trace on
>>> set traced 1
>>>
>>> followed by Owen's code and the simulation. It identified some errors
>>> I could correct by áwrapping up the unwrapped lines . But I am getting
>>> an error now and I can't understand what is causing it. I am providing
>>> the result that I am getting
>>>
>>> - version 11.0
>>> á- if replay() {
>>> á áif "`e(cmd)'" != "coprbt" {
>>> á áerror 301
>>> á á}
>>> á ásyntax [, level(passthru)]
>>> á á}
>>> á- else {
>>> á- syntax varlist [if] [in] , censored(varname) [level(passthru) *]
>>> á- marksample touse
>>> á- preserve
>>> á- qui keep if `touse'
>>> á= qui keep if __000000
>>> á- gettoken depvar indepvars : varlist
>>> á- tempvar newdepvar
>>> á- egen `newdepvar'=group(`depvar')
>>> á= egen __000001=group(y)
>>> á- qui sum `newdepvar'
>>> á= qui sum __000001
>>> á- local maxvalue =r(max)
>>> á- forvalues i=1(1)`maxvalue' {
>>> á= forvalues i=1(1)3 {
>>> á- tempvar ucsample sumucs
>>> á- qui gen `ucsample'=0
>>> á= qui gen __000002=0
>>> á- qui replace `ucsample'=(`censored'!=1) if (`newdepvar'==`i')
>>> á= qui replace __000002=(c!=1) if (__000001==1)
>>> á- qui gen `sumucs'=sum(`ucsample')
>>> á= qui gen __000003=sum(__000002)
>>> á- local errorcount =0
>>> á- capture assert `sumucs'[_N]>0&`sumucs'[_N]<.
>>> á= capture assert __000003[_N]>0&__000003[_N]<.
>>> á- if _rc==9 {
>>> á ádi as error "WARNING: value number `i' has no uncensored obs"
>>> á á}
>>> á- drop `sumucs'
>>> á= drop __000003
>>> á- drop `ucsample'
>>> á= drop __000002
>>> á- }
>>> á- tempvar ucsample sumucs
>>> á- qui gen `ucsample'=0
>>> á= qui gen __000004=0
>>> á- qui replace `ucsample'=(`censored'!=1) if (`newdepvar'==`i')
>>> á= qui replace __000004=(c!=1) if (__000001==2)
>>> á- qui gen `sumucs'=sum(`ucsample')
>>> á= qui gen __000005=sum(__000004)
>>> á- local errorcount =0
>>> á- capture assert `sumucs'[_N]>0&`sumucs'[_N]<.
>>> á= capture assert __000005[_N]>0&__000005[_N]<.
>>> á- if _rc==9 {
>>> á ádi as error "WARNING: value number `i' has no uncensored obs"
>>> á á}
>>> á- drop `sumucs'
>>> á= drop __000005
>>> á- drop `ucsample'
>>> á= drop __000004
>>> á- }
>>> á- tempvar ucsample sumucs
>>> á- qui gen `ucsample'=0
>>> á= qui gen __000006=0
>>> á- qui replace `ucsample'=(`censored'!=1) if (`newdepvar'==`i')
>>> á= qui replace __000006=(c!=1) if (__000001==3)
>>> á- qui gen `sumucs'=sum(`ucsample')
>>> á= qui gen __000007=sum(__000006)
>>> á- local errorcount =0
>>> á- capture assert `sumucs'[_N]>0&`sumucs'[_N]<.
>>> á= capture assert __000007[_N]>0&__000007[_N]<.
>>> á- if _rc==9 {
>>> á ádi as error "WARNING: value number `i' has no uncensored obs"
>>> á á}
>>> á- drop `sumucs'
>>> á= drop __000007
>>> á- drop `ucsample'
>>> á= drop __000006
>>> á- }
>>> á- local k =`maxvalue'-1
>>> á= local k =3-1
>>> á- global OGLFXH "`censored'"
>>> á= global OGLFXH "c"
>>> á- qui oprobit `newdepvar' `indepvars'
>>> á= qui oprobit __000001 áx1 x2 x3
>>> á- tempname starting
>>> á- matrix `starting'=e(b)
>>> á= matrix __000008=e(b)
>>> á- tempname cutvector
>>> á- matrix `cutvector'=`starting'[1,"_cut1".."_cut`k'"]
>>> á= matrix __000009=__000008[1,"_cut1".."_cut2"]
>>>
>>> _cut2 not found
>>>
>>> á áforvalues i=1(1)`k' {
>>> á álocal cut`i'=`cutvector'[1,`i']
>>> á álocal initlist "`initlist' /_cut`i'=`cut`i''"
>>> á álocal cutlist "`cutlist' /_cut`i'"
>>> á á}
>>> á áforeach var of local indepvars {
>>> á álocal `var'_b =`starting'[1,colnumb(`starting',"`var'")]
>>> á á}
>>> á áforeach var of local indepvars {
>>> á álocal initlist "`initlist' `var'=``var'_b'"
>>> á á}
>>> á áml model lf coprbt_ll (`newdepvar'=`indepvars' , nocons ) `cutlist'
>>> á áif `touse' , maximize title("Homemade Censored Ordered Probit")
>>> init(`initlist') `options'
>>> á áereturn local cmd "coprbt"
>>> á á}
>>>
>>> r(111);
>>>
>>> end of do-file
>>>
>>> r(111);
>>>
>>> The "_cut2 not found" is in red suggesting that is where the problem
>>> is, but I cannot figure out what is causing it.
>>>
>>> Any suggestions?
>>>
>>> Thanks a lot.
>>>
>>> Urmi
>>> On Sat, Sep 24, 2011 at 8:14 PM, Austin Nichols <austinnichols@gmail.com> wrote:
>>>> Urmi Bhattacharya <ub3@indiana.edu>:
>>>> I also guess that you have not got the line structure right in your
>>>> files, but I will also note that a quick simulation I ran indicated
>>>> that -oprobit- run only on uncensored obs outperforms unrestricted
>>>> -oprobit- and -coprbit-. áSo start with
>>>>
>>>> . áoprobit y x1 x2 x3 if censored==0
>>>>
>>>> I am also guessing that other models would outperform all 3 options
>>>> mentioned here, but that will have to wait for another day.
>>>>
>>

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index