Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>"String labels" here is informal; Stata does not support value labels for string variables. However, what is wanted here is that the distinct values of a string variable become variable labels on reshaping. </p> <p>Various work-arounds exist. Here's one: put the information in the variable name and then take it out again. </p> <pre><code>clear input entityID str4 indicator str14 indicatordescr indicatorvalue 1 gdp "Gross Domestic" 100 1 pop "Population" 15 1 area "Area" 50 2 gdp "Gross Domestic" 200 2 pop "Population" 10 2 area "Area" 300 end gen what = indicator + "_" + subinstr(indicatordescr, " ", "_", .) keep entityID what indicatorvalue reshape wide indicatorvalue , i(entityID) j(what) string foreach v of var indicator* { local V : subinstr local v "_" " ", all local new : word 1 of `V' rename `v' `new' local V = substr("`V'", strpos("`V'", " ") + 1, .) label var `new' "`V'" } renpfix indicatorvalue </code></pre> <p>EDIT If the length of variable names bites, try another work-around: </p> <pre><code>clear input entityID str4 indicator str14 indicatordescr indicatorvalue 1 gdp "Gross Domestic" 100 1 pop "Population" 15 1 area "Area" 50 2 gdp "Gross Domestic" 200 2 pop "Population" 10 2 area "Area" 300 end mata : sdata = uniqrows(st_sdata(., "indicator indicatordescr")) keep entityID indicator indicatorvalue reshape wide indicatorvalue , i(entityID) j(indicator) string renpfix indicatorvalue mata : for(i = 1; i &lt;= rows(sdata); i++) stata("label var " + sdata[i, 1] + " " + char(34) + sdata[i,2] + char(34)) end </code></pre> <p>LATER EDIT Although the above is called a work-around, it is a much better solution than the previous. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload