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: AW: using extended macros to title graphs
From
Eric Booth <[email protected]>
To
[email protected]
Subject
Re: st: AW: using extended macros to title graphs
Date
Mon, 29 Mar 2010 11:43:01 -0500
>>
>>
I couldn't figure out how to get the outer numeric loop that Nick suggested to work with David's example data/code, but a way I got the title to work is with -levelsof- and looping over the "varlabs" rather than the "vars", ex:
************
*! watch for wrapping issues !*
clear
inp str35 vars str25 varlabs participant_type1 participant_type2 indicator
"children_with_mental_illness_" "Children with MI" .4 .5 1
"communitywide_prevention_init" "Community-wide prevention" .2 .9 0
"differences_between_families_" "Conflict between families " .3 .2 0
"dysfunctional_or_broken_famil" "Dysfunctional " .47 .29 0
"greater_access_to_diversion_o" "Greater access " .2 .5 1
"greater_tolerance_and_cultura" "Greater tolerance " .6 .2 1
"high_levels_of_transience_and" "High levels " .5 .2 0
"holding_juvenile_offenders_mo" "Holding " .4 .4 0
"homeless_youth_face_special_c" "Homeless " .2 .4 0
"immigrant_youth_face_special_" "Immigrant " .2 .3 1
end
*
local tc dysfunctional_or_broken_famil greater_tolerance_and_cultura immigrant_youth_face_special_
levelsof varlabs if indicator==1, loc(tc2)
foreach i in `tc2' {
graph hbar (asis) participant_type1 participant_type2 if indicator==1 & "`i'"==varlabs, ///
nofill bargap(4.5) blabel(bar, size(medium) position(outside) format(%4.2f)) ///
ytitle(%Responses) title("Causes `i'", size(small)) ///
legend(size(vsmall)) name(g1, replace) ///
subtitle(, size(small) span bexpand) graphregion(margin(tiny)) plotregion(margin(vsmall))
}
************
Notice that I changed the condition in the -graph hbar- to " if indicator==1 & "`i'"==varlabs".
~ Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
On Mar 29, 2010, at 11:06 AM, Nick Cox wrote:
> OK. I was trying not to have to read all your code.
>
> You have to fix your outer loop so that it loops over numbers. -vars[text]- won't work unless text is the name of a numeric variable or scalar.
>
> Nick
> [email protected]
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of David Souther
> Sent: 29 March 2010 16:58
> To: [email protected]
> Subject: Re: st: AW: using extended macros to title graphs
>
> Thanks Nick, but this still didn't work for me (this is one of the
> solutions I had tried before posting this question and that I
> mentioned in my reply to Martin Weiss--so I guess I am not too far
> off)
>
>
> On Mon, Mar 29, 2010 at 10:48 AM, Nick Cox <[email protected]> wrote:
>> I guess the problem lies here:
>>
>> title("Causes `=varlabs[`vars[`i']']'")
>>
>> should be
>>
>> title("Causes `=varlabs[`=vars[`i']']'")
>>
>> as the inner and outer macro manipulations are completely independent.
>> Otherwise put,
>>
>> vars[`i']
>>
>> is not the name of a local macro.
>>
>> Nick
>> [email protected]
>>
>> David Souther
>>
>> I am trying to use extended macro functions to title a graph with
>> the value in one string variable that corresponds to another variable.
>>
>> So, a condensed version of my data looks like:
>>
>> clear
>> inp str35 vars str25 varlabs participant_type1 participant_type2
>> indicator
>> "children_with_mental_illness_" "Children with MI" .4 .5 1
>> "communitywide_prevention_init" "Community-wide prevention" .2 .9 0
>> "differences_between_families_" "Conflict between families " .3 .2 0
>> "dysfunctional_or_broken_famil" "Dysfunctional " .47 .29 0
>> "greater_access_to_diversion_o" "Greater access " .2 .5 1
>> "greater_tolerance_and_cultura" "Greater tolerance " .6 .2 1
>> "high_levels_of_transience_and" "High levels " .5 .2 0
>> "holding_juvenile_offenders_mo" "Holding " .4 .4 0
>> "homeless_youth_face_special_c" "Homeless " .2 .4 0
>> "immigrant_youth_face_special_" "Immigrant " .2 .3 1
>> end
>>
>>
>> I want to graph participant_type(s) for specific conditions (one of
>> the "vars" in `tc' and indicator==1) while adding the corresponding
>> "varlabs" title, here's what I tried (and didn't work):
>>
>>
>> local tc dysfunctional_or_broken_famil greater_tolerance_and_cultura
>> immigrant_youth_face_special_
>> foreach i in `tc' {
>> graph hbar (asis) participant_type1 participant_type2 if indicator==1
>> & "`i'"==vars, ///
>> nofill bargap(4.5) blabel(bar, size(medium) position(outside)
>> format(%4.2f)) ///
>> ytitle(%Responses) title("Causes `=varlabs[`vars[`i']']'") ///
>> legend(size(vsmall)) name(g1, replace) ///
>> subtitle(, size(small) span bexpand) graphregion(margin(tiny))
>> plotregion(margin(vsmall))
>> *graph save g1 "g1.gph", replace
>> *graph export "causes_`i'_participanttype.pdf", as(pdf) replace name(g1)
>> }
>>
>>
*
* 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/