Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: RE: Atribute variable value to String

From   "David Radwin" <>
To   <>
Subject   st: RE: Atribute variable value to String
Date   Tue, 22 Feb 2011 16:44:55 -0800 (PST)

Although you say the sectors are strings, the two example values you show
are numeric. Are they all numeric?

If so, perhaps you could (1) change sector to a numeric storage type
(-destring-), (2) -label- each value of sector with the name of that
sector, and then (3) use the extended macro function in the fashion of
-twoway (line Y ano), title("`: variable label sector'")-.

A recent example of (3) is at .

David Radwin
Research Associate
MPR Associates, Inc.
2150 Shattuck Ave., Suite 800
Berkeley, CA 94704
Phone: 510-849-4942
Fax: 510-849-0794

> -----Original Message-----
> From: [mailto:owner-
>] On Behalf Of Lucas Ferreira Mation
> Sent: Tuesday, February 22, 2011 2:36 PM
> To:
> Subject: st: Atribute variable value to String
> 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.
> Another solution would be to create a sector_code sector_name matrix
> in mata (because they are string variables, so a Stata matrix won´t
> accept) and loop over the lines of that matrix. Again, the sector list
> is too big sector for manual entry. So I need a way to import string
> variables from the Stata dataset to the mata matrix. How do I do that?
> The mata command st_data does that but does not work for string
> varibles (it imports them as missing)
> thank you
> Lucas Mation
> Ipea-Instituto de Pesquisa Econômica Aplicada (Brasil)
> *
> *   For searches and help try:
> *
> *
> *

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index