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: Strange -xi- behavior when naming new variables


From   Jorge Eduardo Pérez Pérez <perez.jorge@ur.edu.co>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Strange -xi- behavior when naming new variables
Date   Wed, 18 May 2011 11:07:08 -0400

Thank you for the suggestion. I will be more careful with my loops from now on.
_______________________
Jorge Eduardo Pérez Pérez


On Wed, May 18, 2011 at 4:09 AM, Nick Cox <njcoxstata@gmail.com> wrote:
> If you want to map the string in macro `J' (e.g. "05") to a decimal
> (e.g. .05) then you just do it by references to
>
>   .`J'
>
> That way Stata sees .05 -- which is what you want.
>
> Nick
>
> On Wed, May 18, 2011 at 7:44 AM, Nick Cox <njcoxstata@gmail.com> wrote:
>> Whatever happened, my guess is that it is more likely to be a
>> side-effect of trying to do exact arithmetic with multiples of .05,
>> which will not work on a binary machine.
>>
>> See, most recently,
>>
>> <http://www.hsph.harvard.edu/cgi-bin/lwgate/STATALIST/archives/statalist.1105/date/article-609.html>
>>
>> and beyond that
>>
>> SJ-10-1 pr0051  . . . . . . . . . . . . Stata tip 85: Looping over nonintegers
>>        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
>>        Q1/10   SJ 10(1):160--163                                (no commands)
>>        tip on using forvalues to loop over numbers
>>
>> Try loops over 5(5)95 or 80(5)95. To format leading zeros
>>
>> forval j = 5(5)95 {
>>      local J : di %02.0f `j'
>>     <work with `J'>
>> }
>>
>> Nick
>>
>> 2011/5/18 Jorge Eduardo Pérez Pérez <perez.jorge@ur.edu.co>:
>>
>>> I have been getting strange results using -xi- in conjuction with -qreg-
>>>
>>> I ran the following code to get some quantile regression estimates:
>>>
>>> glo cont "personas_hogar edad edadsq"
>>> glo cat "trabajo_permanente ocupacion actividad_empresa
>>> tipo_trabajador sexo ultimo_grado_estudios"
>>> glo ccat ""
>>> foreach x in $cat {
>>>        glo ccat "$ccat i.`x'"
>>> }
>>> forv x=0.05(0.05)0.9501 {
>>>        xi: qreg lsalario_real_mes treatment i.area2 i.trimestre $cont $ccat
>>> [fw=fex], nolog quantile(`x')
>>>        est save "cqte_c_fex_nob_`x'.ster", replace
>>> }
>>>
>>> The regression for quantile 0.75 did not converge and the loop ended
>>> with a break, so I skipped that quantile, and reran the last loop
>>> starting at the 0.8 quantile, i.e.
>>>
>>> forv x=0.8(0.05)0.9501 { ....
>>>
>>> At this point, -xi- changed the convention for naming the variables.
>>> Since I saved the estimates, I got the command that was issued
>>> everytime by typing:
>>>
>>> glo a: dir . files "cqte_c_fex_nob_*"
>>> foreach x in $a {
>>>        est use `x'
>>>        di "`x' ***********************************"
>>>        di ""
>>>        di e(cmdline)
>>>        di ""
>>> }
>>>
>>> And got:
>>>
>>> cqte_c_fex_nob_.7000000000000001.ster ***********************************
>>>
>>> qreg lsalario_real_mes treatment _Iarea2_* _Itrimestre_*
>>> personas_hogar edad edadsq  _Itrabajo_p_* _Iocupacion_* _
>>>> Iactividad_* _Itipo_trab_* _Isexo_* _Iultimo_gr_* [fw=fex], nolog quantile(.7000000000000001)
>>>
>>> cqte_c_fex_nob_.8.ster ***********************************
>>>
>>> qreg lsalario_real_mes treatment _Iarea2_* _Itrimestre_*
>>> personas_hogar edad edadsq  _Itrabajo_p_* _Iocupaciona* _
>>>> Iactividad_* _Itipo_trab_* _Isexo_* _Iultimo_gr_* [fw=fex], nolog quantile(.8)
>>>
>>> Notice the difference between the two commands: _Iocupacion_* and
>>> _Iocupaciona*_ !!!!
>>>
>>> Is this something related to some variables left behind by -xi- when
>>> the break occurred? Could this be a bug?
>>>
>>
>
> *
> *   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/
>

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