LATER EDIT Although the above is called a work-around, it is a much better solution than the previous. Mata : for(i = 1 i <= rows(sdata) i++) stata("label var " + sdata + " " + char(34) + sdata + char(34)) Reshape wide indicatorvalue, i(entityID) j(indicator) string Mata : sdata = uniqrows(st_sdata(., "indicator indicatordescr")) )ĮDIT If the length of variable names bites, try another work-around: clear Reshape wide indicatorvalue, i(entityID) j(what) string Gen what = indicator + "_" + subinstr(indicatordescr, " ", "_". Both of these variables have a numeric part. In our dataset, there are 2 variables which are INC and UE. After that, we have to specify the names of the variables which are in the wide format. reshape wide inc, i(id) j(year) / goes from right form to left / Because we did not specify sex in the command, Stata assumes that it is constant within the logical observation, here id. Since we need to convert the data from a wide format to a long format, this is why the command that we wrote was reshape long. reshape long inc, i(id) j(year) / goes from left form to right /. entityID indicator indicatordescr indicatorvalue 1 gdp Gross Domestic 100 1 pop Population 15 1 area Area 50 2. Input entityID str4 indicator str14 indicatordescr indicatorvalue Given these data, you could use reshape to convert from one form to the other. I have dataset in Stata that looks like this. Here's one: put the information in the variable name and then take it out again. However, what is wanted here is that the distinct values of a string variable become variable labels on reshaping. "String labels" here is informal Stata does not support value labels for string variables. NB: the variable labeling after reshape must be done programatically, because indicator and indicatordescr have many values.
#RESHAPE STATA HOW TO#
I have looked at this : Bring value labels to variable labels when reshaping wideīut did not understand how to apply those to my case. Unfortunately, as I understand, it is not possible to assign the value of indicatordescr as a value label of indicator, so the reshape can't transform these value labels into variable labels. Where I would like gdp variable label to be "Gross Domestic", pop label "Population" and area "Area". Reshape from long to wide in R is also achieved using spread () and cast () function. Reshape from wide to long in R is also achieved using gather () and melt () function. We have discussed melting and casting in R which is another way of transforming data. I have dataset in Stata that looks like this entityID indicator indicatordescr indicatorvalueĪnd there is a one-to-one mapping between values of indicator and values of indicatordescr. Reshape in R reshape (), is one of the efficient function to transform the data.