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: RE: Atribute variable value to String


From   Lucas Ferreira Mation <[email protected]>
To   [email protected]
Subject   Re: st: RE: Atribute variable value to String
Date   Wed, 23 Feb 2011 16:32:26 -0300

Dear Nick, David and Christopher, thank you very much for the answers,
ecxactly what I needed. Bellow is the debuged code to make loops with
graphs of subsections of the data (in this case by sector) and
changing the titles in each iteration.

Two questions remain:

1) how do I directly  atribute the value of a variable in a specific
line to a scalar? (an indirect aproach would be to to atribute that
value to a labe (egen ...=group(...), label ) and then atribute that
to the scalar)

2) how do I atribute the value in a cell in a mata matrix to a Stata
scalar (I know you could bring that matrix to the database).

again tks
Lucas Mation
Ipea-Instituto de Pesquisa Econômica Aplicada (Brasil)




* schematic data
input str20 sector_code str20 sector_name Y year
	s1 "industry" 1 2000
	s1 "industry" 2 2001
	s2 "commerce" 5 2000
	s2 "commerce" 4 2001
	end

*Aproach 1: atribute sector_name to lebel of a new var (Nick Cox's sugestion):
egen sec_name_group = group(sector_name), label
egen sec_code_group = group(sector_code), label
su sec_name_group, meanonly
cd "C:\...\graphs"
forval i = 1/`r(max)' {
    twoway line Y year if[sec_name_group==`i'], title("`: label
(sec_name_group) `i' '")
	graph export y_year_`: label (sec_code_group) `i' '.wmf
	}


*Aproach 2: create dataset with the details of each graph iteration
(sector restrictions,titles, notes, options), send that information to
a matrix and loop over that matrix. This is indirect but could be very
convinient if you had several details changing per graph. For this to
work however I need  atribute the value in a cell in a mata matrix to
a stata scalar



On Tue, Feb 22, 2011 at 10:46 PM, Nick Cox <[email protected]> wrote:
> If I understand this correctly, the problem need not involve putting
> data into Mata only to have to pull them out again.
>
> There are various more direct solutions. Here is one. See also
>
> http://www.stata.com/support/faqs/data/foreach.html
>
> egen group = group(clas_cnae), label
> su group, meanonly
>
> forval i = 1/`r(max)' {
>        twoway line Y ano if group == `i', title("`: label (group) `i''")
> }
>
> You will presumably want to save those graphs too.
>
> Nick
>
> Lucas Ferreira Mation
>
>>> I have a dataset with the variables: sector_code sector_name year Y
>>> I want to create the graph line  Y year   for each sector. As there
>>> are too many sectors (500) , i want to make a loop like:
>>> global sector_list 01112 01120 // the actual list is much longer
>>> foreach s in $sector_list {
>>> preserve
>>>       keep if clas_cnae=="`s'"
>>>       twoway (line Y ano) , title ( /* SOMEHOW THE VALUE IN VARIABLE
>>> sector_name*/)
>>> restore
>>> }
>>> How can I do that? I guess my question is equivlent to: how to
>>> atribute the content of a string variable to a scalar (which I could
>>> later use in the loop)? That would be the easyest way if I knew how.
>
> [...]
>
> *
> *   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index