Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: AW: AW: AW: AW: AW: AW: AW: Detach value label from string var


From   "Kaulisch, Marc" <kaulisch@forschungsinfo.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: AW: AW: AW: AW: AW: AW: Detach value label from string var
Date   Wed, 7 Apr 2010 19:05:28 +0200

Martin,

Thanks a lot for this excellent solution.

It bites me when I try to reduce the number of value labels because I cannot label strings ;-)

My change (see below) does not work.
****
findname, type(string) vall

la de vall_str 0 "t"

foreach var of varlist `r(varlist)' {
la value `var' vall_str
}
****

and using -labeldup- (user-written program) after defining value labels attached to strings creates the same error.
-labeldup- works well when the labels are not defined ;-)


Marc


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
Gesendet: Mittwoch, 7. April 2010 18:37
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: AW: AW: AW: AW: AW: Detach value label from string var


<> 


" ds, has(type string)
ds `r(varlist)', has(vallabel)"



Or, in one fell swoop, with Nick`s recent ssc contribution -findname-:



*************
cap which findname
if _rc ssc inst findname
findname, type(string) vall
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
Gesendet: Mittwoch, 7. April 2010 18:35
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: AW: AW: AW: AW: Detach value label from string var


<> 

So here is a way to fake-define a -value label- for the string vars that (seem to) have a -value label-. The example follows from the fake dataset created in my earlier conversation with Marc:


*************
clear*
xmluse stata_out.xml

ds, has(type string)
ds `r(varlist)', has(vallabel)

foreach var of varlist `r(varlist)'{
	cap la de `:value label `var'' 0 "test" 1 "test1"
	di in r "Now at value label: `:val la `var'', RC is: " _rc }
*************

The example shows the value of -ds- once again. We need to -capture- the creation of the -label- since the same -label- may well be attached to two different variables, as is the case in my example. In the second line, the return code shows whether there was a problem or not.


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Kaulisch, Marc
Gesendet: Mittwoch, 7. April 2010 18:20
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: AW: AW: AW: Detach value label from string var

Martin,

I certainly can reproduce the behaviour with your example. So I get the point that "string vars with embedded blanks" has nothing to do with the value labels attached to string vars. But I get problems with empty value labels attached to string vars.

For example
. mlanguage add val, saving(val) // mlanguage is a user-written program Produces an error because mylabel is not defined. Info: -labelbook, p- does not see a problem in this example.

It is possible to define mylabel
. la de mylabel 0 "test" 1 "test1"

Then: -mlanguage- works.

So a solution to my problem would be to define all value labels attached to a string var. Another solution would be to do not attach empty value labels to string vars in the first place (my favorite solution).

Or on Stata-side
- to improve the XML-Import that either such attachements to string vars are ignored or an error while importing is shown
- to allow the detachment of value labels from string vars


Marc

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
Gesendet: Dienstag, 6. April 2010 18:47
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: AW: AW: Detach value label from string var


<> 

It is indeed a little weird that one can attach a -value label- to a string variable with -xmluse-, which is certainly not possible via the "variables manager" - where the necessary button is disabled for string variables. I am not sure whether this behavior has any real bearing on your "string var with embedded blanks issue", though. Try this:

*************
sysuse auto, clear
gen str1 newstrvar=cond(_n<50,"A","B")
xmlsave stata_out.xml, doctype(dta) replace !start stata_out.xml
*************

At this point, you edit lines 62 and 74 of the resulting xml file to read:

<lblname varname='make'>mylabel</lblname>

and 

<lblname varname='newstrvar'>mylabel</lblname>

respectively. 


You save the xml file and continue:

*************
clear*
xmluse stata_out.xml
d
codebook, p
*************


The result is:


. codebook, p

   Potential problems in dataset   stata_out.xml

               potential problem   variables
--------------------------------------------------
  strvars that may be compressed   make
string vars with embedded blanks   make
--------------------------------------------------


This result leads me to believe that "string vars with embedded blanks" has nothing to do with the value labels attached to string vars, and everything with the values of the variable itself. Otherwise, "newstrvar" would have to show up in the -codebook- results as well.


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Kaulisch, Marc
Gesendet: Dienstag, 6. April 2010 18:17
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: AW: Detach value label from string var

We import our data by a XML-file where <lbllist> is given for all vars (e.g.
<lblname varname='BN15_2__5'>BN15_2</lblname>) despite (non-)existing value labels defined under <value labels>.

A trick would be to remove the value labels for all string vars in the XML-definition <lblname>. I hoped to do this by a Stata command and not going back to our contractor changing the export-mechanism...

Marc

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
Gesendet: Dienstag, 6. April 2010 16:35
An: statalist@hsphsun2.harvard.edu
Betreff: st: AW: Detach value label from string var


<> 


What does "importing a dataset" mean? The effect does not seem to occur
here:


*************
sysuse auto, clear
outsheet using myfile.csv, comma replace
clear*
insheet using myfile.csv, comma clear
d
la dir
codebook, p
*************

-codebook- returns "make" as a "string var with embedded blanks", but how is this issue connected to any -label-?


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Kaulisch, Marc
Gesendet: Dienstag, 6. April 2010 15:32
An: statalist@hsphsun2.harvard.edu
Betreff: st: Detach value label from string var

Another problem I cannot solve myself:
By importing a dataset all variables get label values attached - also string vars. This leads to "string vars with embedded blanks" by codebook, p.

For numeric vars with empty value labels I used:
. label values `r(labelnotfound)' .

But
. label values `r(str_embedded)' .
does not work. 

I even can not do this via the Variables Manager. Any idea how to do this?



*
*   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/

*
*   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/

*
*   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/


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index