Bookmark and Share

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


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

Re: st: egen with user-defined function


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: egen with user-defined function
Date   Tue, 20 Aug 2013 01:40:54 +0100

I don't see quite what -egen- is objecting to here but you have more
fundamental problems.

Wiring in particular names to a program is not illegal but it usually
implies that you are pitching your problem at the wrong level.

(*) I guess that you have some variable -RECORD_AXIS_DATA- and you are
looking for occurrences of the strings "A410" ... "A419".

Your code would at most look in the first observation as you are using
the -if- command
instead of an -if- qualifier.

It would be probably be best if you described the concrete problem, as
my strong guess is that no original program is needed here.

But I'll guess that (*) is the nub of the problem.

clonevar copy = RECORD_AXIS_DATA

qui forval i = 0/9 {
      replace copy = subinstr(copy, "A41`i'", "", .)
}

gen count = (length(RECORD_AXIS_DATA) - length(copy)) / 4

So in a copy of the variable we replace each occurrence of "A410"
"A411" ... "A419" with an empty string. Each such deletion reduces the
number of characters by 4.

This was written up in http://www.stata-journal.com/article.html?article=dm0056


Nick
[email protected]


On 20 August 2013 01:03, Jan Barendregt <[email protected]> wrote:

> I'm trying to let egen to use a user-defined function. Here is what I'm doing:
>
> do "C:\Ddrive\MattCooper\Data\test.do"
>
> . capture program drop _grecordparse
>
> . program define _grecordparse
>   1. local bool=0
>   2. local li=1
>   3. local i=0
>   4.   while `i' < RECORD_AXIS_COUNT {
>   5.   if (substr(RECORD_AXIS_DATA,`li',4)>="A410") & (substr(RECORD_AXIS_DATA,`li',4)<="A419") local bool=
>> `bool'+1
>   6.   local li=`li'+4
>   7.   local i=`i'+1
>   8.   }
>   9.   gen `typlist' `varlist' = `bool'
>  10. end
>
> .
> end of do-file
>
> . egen sepsis=recordparse
> unknown egen function recordparse()
> r(133);
>
>
> So I can't get egen to recognise my recordparse function. Any ideas?
>
> I'm using Stata 11.2 on Windows
>
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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