Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: notes lost in append


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: notes lost in append
Date   Tue, 11 May 2004 15:49:04 +0100

As said previously, I too could not see how to implement 
Fred's suggestion. 

-notes- are characteristics (and not variables of any 
kind). 

The only easy way forward I can see is to save notes
as string variables. 

The following code is based on the following assumptions: 

1. If the user types 

. savenotes <stub> 

then <stub>__dta will be a legal new variable name whenever there 
are notes associated with the dataset and each 
<stub>_<varname> will be a legal new variable name
for each <varname> for which there are notes. 

2. The longest note can fit into the longest string
variable available in your version of Stata. 

3. There aren't more notes than observations. 

4. Extra assumptions I haven't thought of. 

*! NJC 1.0.0 11 May 2004
program savenotes
	version 8 
	syntax name(name=stub) 
	
	qui { 
		local nnotes "`: char _dta[note0]'" 
		if "`nnotes'" != "" gen `stub'__dta = "" 
		forval i = 1/`nnotes' { 
			replace `stub'__dta = `"`: char _dta[note`i']'"' in `i' 
		} 

		foreach v of var * { 
			local nnotes "`: char `v'[note0]'" 
			if "`nnotes'" != "" { 
				gen `stub'_`v' = "" 
				forval i = 1/`nnotes' { 
					replace `stub'_`v' = ///
					`"`: char `v'[note`i']'"' in `i' 
				} 
			} 
		} 
	} 	
end 
			
*! NJC 1.0.0 11 May 2004
program usenotes
	version 8 
	syntax name(name=stub) 
	
	qui { 
		foreach v of var `stub'_* { 
			local V : subinstr local v "`stub'_" ""
			count if `v' != "" 
			forval i = 1/`r(N)' { 
				if "`V'" == "_dta" notes : `"`=`v'[`i']'"' 
				else notes `V' : `"`=`v'[`i']'"' 
			} 	
		} 
	} 	
 	
end 

So what could you do? 

In a dataset, if you type 

savenotes stub

then you will save the notes in string variables
like stub__dta (double underscore) and stub_mpg. 

In a modified dataset containing these variables, 

usenotes stub 

will define new (N.B. extra) notes. 

In other words, the string variables are just luggage
in which you carry your notes from one place to another. 

This doesn't directly address Devra's -append- question
but I think it should help. 
			
Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Devra Golbe
> Sent: 11 May 2004 14:49
> To: [email protected]
> Subject: Re: st: RE: notes lost in append
> 
> 
> I thank Fred and Nick for their responses to my question 
> about appending notes.
> 
>   For the short-term, I would be happy to try Fred's 
> suggestion if only I 
> could figure out how to do it.  Having checked the 
> documentation, I can't 
> see how to retrieve the notes from a data set in order to 
> copy them into a 
> new data set.  Are they stored in some retrievable variable?
> 
> For the long-term, I think it would be useful if  -append- 
> retained notes 
> in the using data set, renumbering if necessary, and, if 
> feasible, adding 
> an option to add the source data set to the note.
> 
> At 02:25 PM 5/8/2004,  Fred Wolfe  wrote:
> >I think there is a possible work-around. As notes are stored as 
> >-var[note(n)]:-, one could pull off the notes from each data 
> set prio to 
> >the append/merge, compare them and then merge them into the 
> master set 
> >according to some rule. I could see how this might be useful.
> >
> >Fred
> >
> >At 12:45 PM 5/8/2004,  Nick Cox  wrote:
> >>What kind of work-around are you expecting?
> >>
> >>Stata's problem, I think, is that it expects at most one
> >>note for each combination of name and number, e.g. "mpg"
> >>and "1".
> >>
> >>In addition, as the variables in the datasets typically
> >>have the same names -- little point in -append-ing
> >>otherwise -- it is difficult to think of a work-around
> >>other than having unique variable names in each dataset,
> >>to each of which you attach -notes-. I haven't tested that.
> >>
> >>A clumsier alternative is to store text in a string
> >>variable in each dataset.
> >>
> >>Devra Golbe
> >>
> >> > I would like to append two data files each having notes.  As
> >> > the output
> >> > below indicates,  notes from the "using" file are evidently
> >> > not retained
> >> > when the master file already contains notes on the same
> >> > variable.  The same
> >> > is true for a note attached to the file as a whole:  while it
> >> > is possible
> >> > to have multiple notes, if the master file contains such
> >> > notes, none are
> >> > retained from the using file.
> >> >
> >> > Does anyone know of a work-around?
> >> >
> >> > Thanks,
> >> > Devra
> >> >
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index