Hi,
I am very new to writing programs in Stata. My current project is to write an ado-file to get the mean of a variable conditional on a time period (I know this is already possible with built in commands).
I have the following dataset and want to calculate the mean price for a specified time period.
so in the end I want to type for example progname price if inrange(year,2004,2008) to get the mean price between 2004 and 2008. (Actually the program is supposed to give me means, 95ci and export everything to excel, but one problem at a time).
What I cannot figure out is how to get the if-condition into the program.
The basic version from where I started is:
where in the program do I specify the year(s) and how would you suggest to do it?
Thank you for your help
Kind regards
Magnus
I am very new to writing programs in Stata. My current project is to write an ado-file to get the mean of a variable conditional on a time period (I know this is already possible with built in commands).
I have the following dataset and want to calculate the mean price for a specified time period.
Code:
year price 2002 20 2003 21 2004 19 2005 18 2006 21 2007 22 2008 20 2009 21
What I cannot figure out is how to get the if-condition into the program.
The basic version from where I started is:
Code:
cap program drop pmean program pmean, rclass version 15 syntax varlist [if] [in] qui sum `1' return list end
Thank you for your help
Kind regards
Magnus
Comment