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: Running a model using global macro statement


From   Sam Asin <[email protected]>
To   [email protected]
Subject   Re: st: Running a model using global macro statement
Date   Tue, 3 Sep 2013 17:09:31 -0400

Thanks!  I'm sorry I misunderstood earlier... I thought you were
pointing to the quotes in between each thing to make the spaces.  I
get it now.  Thanks for taking the time to clear that up for me!

Sam

On Tue, Sep 3, 2013 at 4:47 PM, Eric A. Booth <[email protected]> wrote:
> <>
> Again, you dont need the quotes in the regressionstatement global
> macro at all.  When I run your code:
>
> This statement:
>
> global regressionstatement $regtype $dependentvar collection2 $zipind
> $dateind $kenparam $ifstatement,  $options
> di `"${regressionstatement}"'
> set trace on
> ${regressionstatement}
> set trace off
>
> produces this output, which is what you want (the > line continuations
> are not removed below):
>
>  mlogit eventmulti 90 collection2 i.zipspecial i.date dage1-dage8
> cohort96 cohort97 c
>> ohort98 cohort99 cohort00 cohort01 cohort02 cohort03 cohort04 cohort05 cohort06 cohort07
>> cohort08 ltv1 ltv2 ltv3 ltv4 ltv5 fico1 fico2 fico3 fico4 xfc11 xfc12 xfc13 xfc14 xfc21 x
>> fc22 xfc23 xfc24 xfc31 xfc32 xfc33 xfc34 xfc41 xfc42 xfc43 xfc44 oupb1-oupb4 fdti1 fdti2
>> fdti3 fdti4 bdti1 bdti2 bdti3 bdti4 sato1-sato2  second_lien metro units condo ,
>
>
> When I run the code you provided (with the quotes), you do _not_ get a
> -mlogit- command that Stata can understand (hence the error) because
> there are still quotes around all the sets of variables.
>
> Your current code is:
>
> global regressionstatement "$regtype" "$dependentvar" " collection2 "
> "$zipind" "$dateind" "$kenparam" "$ifstatement" ", " "$options"
> di `"${regressionstatement}"'
> ${regressionstatement}
>
> Which produces this ... this is not right:
>
>     mlogit eventmulti" "90" " collection2 " "i.zipspecial" "i.date"
> "dage1-dage8 cohort9
>> 6 cohort97 cohort98 cohort99 cohort00 cohort01 cohort02 cohort03 cohort04 cohort05 cohort
>> 06 cohort07 cohort08 ltv1 ltv2 ltv3 ltv4 ltv5 fico1 fico2 fico3 fico4 xfc11 xfc12 xfc13 x
>> fc14 xfc21 xfc22 xfc23 xfc24 xfc31 xfc32 xfc33 xfc34 xfc41 xfc42 xfc43 xfc44 oupb1-oupb4
>> fdti1 fdti2 fdti3 fdti4 bdti1 bdti2 bdti3 bdti4 sato1-sato2  second_lien metro units cond
>> o" "" ", " "
>
>  You are lulled into thinking there are no quotes in your -mlogit-
> command produced by ${regressionstatement} because when you -display-
> the macro you do not see them because you dont specify your -display-
> correctly. That is,  you currently use this code to -display-  :
>
> di "${regressionstatement}"
>
> and you get a "clean" list of variables (meaning no quotes) but that
> isnt correct, it really isnt clean, but you only see that if you run:
>
> di `"${regressionstatement}"'
>
>
> which is why I pointed you to the double quotes discussion in -help
> quotes- in my previous post. When you dont use "double compound
> quotes" around these macros nested in another macro, Stata cannot
> properly parse the statement.
>
> Consider a simple example:
>
> sysuse auto, clear
> global one  "regress"
> global two   "mpg"
> global three  "price"
>
> global  right  $one $two $three
> di `"$right"'
> di "$right"
>
> You dont have any quotes on the macros stored in $right, so both of
> these are equivalent:
>
> . di `"$right"'
> regress mpg price
>
> . di "$right"
> regress mpg price
>
> and this would run without error:
>
> $one $two $three
> global all $one $two $three
> $all
> di `"$all"'
>
> this all works fine.
>
>
>
>
> However, with quotes around your global macros one-three you run this:
> **
> global  wrong  "$one" "$two" "$three"
> di "$wrong"
>
> which produces this output:
>
> . di "$wrong"
> regressmpgprice
>
> without any spaces since you excluded the double quotes.  This is why
> you are trying to manually put those spaces in to your global
> regression statement.
> But it doesnt help because really the problem is that Stata cannot
> differentiate  where your quotes start and stop (or how the bind
> together your strings).  In the Stata help file I pointed you to,
> there a great discussion that poses a similar problem, saying:
>
>       (What does "A"B"C" mean?  Either it means `"A`"B"'C"' or it
> means `"A"'B`"C"'.)
>
> You need double compound quotes to display what Stata is actually
> sending to your ${regressionstatement}:
>
> di `"$wrong"' //Stata is keeping the internal quotes
>
> . di `"$wrong"'
> regress" "mpg" "price
>
> Notice the internal quotes are retained.  You do not want/need these.
>
>
>
> On Tue, Sep 3, 2013 at 12:56 PM, Sam Asin <[email protected]> wrote:
>> Thanks for your prompt, helpful responses!  I was wondering if it was
>> an issue with the quotes and spaces, but for whatever reason, the
>> spaces aren't automatically being input correctly.  Here is a snippet
>> from the do file:
>>
>>                 *Ken Parameters (Commented out means probably will
>> never be used, see below line for actual specification for model)
>>         global dage "dage1-dage8"
>>         global cohorts "cohort96 cohort97 cohort98 cohort99 cohort00 cohort01
>> cohort02 cohort03 cohort04 cohort05 cohort06 cohort07 cohort08"
>>         global standard " second_lien metro units condo"
>>         global oltv "ltv1 ltv2 ltv3 ltv4 ltv5"
>>         global ofico "fico1 fico2 fico3 fico4"
>> //      global interx "x_fico_ltv_dti"
>> //      global refib "yt*"
>>         global fc "xfc11 xfc12 xfc13 xfc14 xfc21 xfc22 xfc23 xfc24 xfc31
>> xfc32 xfc33 xfc34 xfc41 xfc42 xfc43 xfc44"
>>         global fdp "fico_ltv_11 fico_ltv_12 fico_ltv_13 fico_ltv_14
>> fico_ltv_15 fico_ltv_21 fico_ltv_22 fico_ltv_23 fico_ltv_24
>> fico_ltv_25 fico_ltv_31 fico_ltv_32 fico_ltv_33 fico_ltv_34
>> fico_ltv_35 fico_ltv_41 fico_ltv_42 fico_ltv_43 fico_ltv_44
>> fico_ltv_45"
>>         global oupb "oupb1-oupb4"
>>         global sato "sato1-sato2"
>> //      global census "st_midatlantic st_eastnorcent st_westnorcent
>> st_eastsocent st_westsocent st_mountain st_pacific st_newengland"
>> //      global rule "st_rule2-st_rule4"
>>         global dti "fdti1 fdti2 fdti3 fdti4 bdti1 bdti2 bdti3 bdti4"
>>
>> ********************************* KEN PARAMETER CHOICE ************************
>> **********                                                          ***********
>> global kenparam $dage $cohorts $oltv $ofico $fc $oupb $dti $sato $standard
>>
>>
>>
>>
>> global zipind "i.zipspecial"
>>         global zipindproportion .25
>>
>> global dateind "i.date"
>> global regtype "mlogit eventmulti"
>> global dependentvar "90"
>>
>> global regressionstatement "$regtype" "$dependentvar" " collection2 "
>> "$zipind" "$dateind" "$kenparam" "$ifstatement" ", " "$options"
>>
>>
>>
>> and the snippet from the command window:
>>
>>
>> . global regressionstatement "$regtype" "$dependentvar" " collection2
>> " "$zipind" "$dateind" "$kenparam" "$ifstatement" ", " "$options"
>>
>>
>>
>> . display "$regressionstatement"
>> mlogit eventmulti90 collection2 i.zipspeciali.datedage1-dage8 cohort96
>> cohort97 cohort98 cohort99 cohort00 cohort01 cohort02 cohort03 coh
>>> ort04 cohort05 cohort06 cohort07 cohort08 ltv1 ltv2 ltv3 ltv4 ltv5 fico1 fico2 fico3 fico4 xfc11 xfc12 xfc13 xfc14 xfc21 xfc22 xfc23 xf
>>> c24 xfc31 xfc32 xfc33 xfc34 xfc41 xfc42 xfc43 xfc44 oupb1-oupb4 fdti1 fdti2 fdti3 fdti4 bdti1 bdti2 bdti3 bdti4 sato1-sato2  second_lie
>>> n metro units condoif def_obs_count<2, constant tolerance(1e-8)
>>
>> Note that I had to put spaces around "collection2" in the macro to
>> make it show up correctly, and the i.zipspecial and i.date variables
>> are still messed up.  This is all odd, because above I defined
>> $kenparam in the manner that you specified and had no need to add
>> spaces, but for some reason on $regressionstatement I need to add
>> spaces.
>>
>> Thanks,
>>
>> Sam
>>
>>
>>
>> On Tue, Sep 3, 2013 at 11:16 AM, Eric A. Booth <[email protected]> wrote:
>>> <>
>>>
>>> Apologies, I hit 'send' early on my last email.... the last point was
>>> showing how your model runs once you strip away the double compound
>>> quotes, consider:
>>>
>>>
>>>  global regtype logit
>>>  global dependentvar event90
>>>  global collection2 i.zipspecial i.date
>>>  global zipind dage1-dage8
>>>
>>> global regressionstatement "$regtype" "$dependentvar" " "
>>> "collection2" " " "$zipind" " "
>>> di "${regressionstatement}" // versus:
>>> di `"${regressionstatement}"'
>>> *! this is not what you want.
>>>
>>> ****instead try this
>>> global regressionstatement  $regtype $dependentvar $collection2 $zipind
>>>
>>> di `"${regressionstatement}"'
>>> ${regressionstatement} //this works.
>>>
>>>
>>> - Eric
>>>
>>>
>>> On Tue, Sep 3, 2013 at 10:13 AM, Eric A. Booth <[email protected]> wrote:
>>>> <>
>>>> This a issue with the quotes. Your global regressionstatement doesnt
>>>> need all those quotes around the globals, nor the extra set of quotes
>>>> to embed spaces.  First, you should read the -help quotes- file about
>>>> double compound quotes because it's useful anytime you are working
>>>> with macros that contain multiple quotes or nested quotes as you are
>>>> attempting to do.  But in this case the issue is that you just do not
>>>> need quotes at all.  Nesting your globals in the
>>>> ${regressionstatement} without quotes will insert the proper spaces.
>>>>
>>>> So
>>>>
>>>>
>>>>
>>>>
>>>> On Tue, Sep 3, 2013 at 9:45 AM, Sam Asin <[email protected]> wrote:
>>>>> Hello, this is my first post here!
>>>>>
>>>>> I am trying to create a do file that runs a logit command.  I use a
>>>>> global macro statement to set up the regression, it's called
>>>>> $regressionstatement.
>>>>>
>>>>> global regressionstatement "$regtype" "$dependentvar" " "
>>>>> "collection2" " " "$zipind" " " "$dateind" " " "$kenparam"
>>>>> "$ifstatement" ", " "$options"
>>>>>
>>>>>
>>>>>
>>>>> At the bottom of my code, it invokes $regressionstatement.  However, I
>>>>> get this error:
>>>>>
>>>>> 2" " invalid name
>>>>> r(198);
>>>>>
>>>>>
>>>>>
>>>>> However, if I write:
>>>>>
>>>>> display "$regressionstatement"
>>>>>
>>>>>
>>>>> and then copy paste the output onto my command line and run it, it
>>>>> works.  I also tried:
>>>>>
>>>>> "$regressionstatement"
>>>>>
>>>>> to no avail, as well as:
>>>>>
>>>>> global test "$regressionstatement"
>>>>>
>>>>> $test
>>>>>
>>>>> How can I make my code run the regressoin statement that I've made
>>>>> without requiring the additional manual input?  For what it's worth,
>>>>> I've included the code of interest below.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> global regressionstatement "$regtype" "$dependentvar" " "
>>>>> "collection2" " " "$zipind" " " "$dateind" " " "$kenparam"
>>>>> "$ifstatement" ", " "$options"
>>>>>
>>>>>  display "$regressionstatement"
>>>>> logit event90 collection2 i.zipspecial i.date dage1-dage8 cohort96
>>>>> cohort97 cohort98 cohort99 cohort00 cohort01 cohort02 cohort03
>>>>> cohort04 cohort05 cohort06 cohort0
>>>>>> 7 cohort08 ltv1 ltv2 ltv3 ltv4 ltv5 fico1 fico2 fico3 fico4 xfc11 xfc12 xfc13 xfc14 xfc21 xfc22 xfc23 xfc24 xfc31 xfc32 xfc33 xfc34 xfc41 xfc42 xfc43 xfc44 oupb1-
>>>>>> oupb4 fdti1 fdti2 fdti3 fdti4 bdti1 bdti2 bdti3 bdti4 sato1-sato2  second_lien metro units condo if def_obs_count<2, vce(robust)
>>>>> .
>>>>> $regressionstatement
>>>>> 2" " invalid name
>>>>> logit event90 collection2 i.zipspecial i.date dage1-dage8 cohort96
>>>>> cohort97 cohort98 cohort99 cohort00 cohort01 cohort02 cohort03
>>>>> cohort04 cohort05 cohort06 cohor
>>>>>> t07 cohort08 ltv1 ltv2 ltv3 ltv4 ltv5 fico1 fico2 fico3 fico4 xfc11 xfc12 xfc13 xfc14 xfc21 xfc22 xfc23 xfc24 xfc31 xfc32 xfc33 xfc34 xfc41 xfc42 xfc43 xfc44 oupb
>>>>>> 1-oupb4 fdti1 fdti2 fdti3 fdti4 bdti1 bdti2 bdti3 bdti4 sato1-sato2  second_lien metro units condo if def_obs_count<2, vce(robust)
>>>>> note: 33890.zipspecial != 0 predicts success perfectly
>>>>>       33890.zipspecial dropped and 60 obs not used
>>>>>
>>>>> etc.
>>>>>
>>>>>
>>>>> Thanks!
>>>>>
>>>>> Sam
>>>>> *
>>>>> *   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/
>>> *
>>> *   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/
>> *
>> *   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/
> *
> *   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/
*
*   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