 
    A. Colin Cameron: Anaconda
Anaconda is the standard front-end to Python
      
        
      
INSTALL
          ANACONDA FOR MAC WITH M1/M2 PROCESSOR
        
        See special directions at the bottom
          of this page. 
           
        
INSTALL
          ANACONDA 
Uninstall any existing Anaconda and Python packages.
Download Anaconda from Anaconda site
Choose Administrative if you have Administrative
        Privileges (this puts Anaconda in a more natural folder)
Once downloaded (takes a while) have it installed (takes
        a while). 
Start Anaconda
It may ask you to update to a newer version.
What is Anaconda?
            Anaconda is a front-end to python. It is software to install
            and manage Python, Python packages, and other programming
            languages (such as R). It can
            be used to run a Python program.
https://docs.anaconda.com/anaconda/
PYTHON PACKAGES –
          NumPy, pandas, SciPy, matplotlib, statsmodels, scikit-learn (Sklearn)
Python is a programming language. Basic Python is not
        set up for data analysis. For example, It does not even support
        arrays. 
Instead one uses Python packages. Anaconda loads in
        several hundred Python packages.
For a list see https://docs.anaconda.com/anaconda/packages/pkg-docs/
        
Key data analysis packages for data analysis that are
        downloaded by Anaconda are the following.
        
    - pandas. Name derived from panel data. R
        type data frames and data analysis tools.
           - matplotlib. Static and dynamic data
        visualizations.
           - SciPy. Scientific library (optimization,
        integration, eigenvalue problems, random number generators, ...)
           - statsmodels. Statistics using pandas dataframes
        (computations and models including standard regression models).
           - scikit-learn (Sklearn). Machine learning and data
        mining using NumPy arrays.
           - TensorFlow. Deep learning such as neural
        networks.
        Commands for many of these modules have similar format to R
        commands.
ANACONDA
          NAVIGATOR FOR PACKAGES
In
order
          to run, many scientific packages depend on specific versions
          of other packages. Data scientists often use multiple versions
          of many packages and use multiple environments to separate
          these different versions. 
          The command-line
            interface program conda is both a
          package manager and an environment manager. This helps data
          scientists ensure that each version of each package has all
          the dependencies it requires and works correctly. Examples:
          conda remove pandas   conda install pandas 
          conda update pandas
          Navigator is a graphical interface
          that enables you work with packages and environments without
          needing to type conda commands in a terminal window. You can
          use it to find the packages you want, install them in an
          environment, run the packages, and update them – all inside
          Navigator. https://docs.anaconda.com/navigator/
RUNNING CODE WITH
          ANACONDA NAVIGATOR
          
There are several ways. 
        Spyder is a GUI or IDE interface.  From the Navigator Home
        page, click the Spyder tile, and use the Spyder interface that
        opens to write and execute your code.
        You
          can also use Jupyter Notebook the same way. Jupyter Notebook
          is an increasingly popular system that combines your code,
          descriptive text, output, images, and interactive interfaces
          into a single notebook file that is edited, viewed, and used
          in a web browser.  https://docs.anaconda.com/navigator/
        
           CREATING AND
              CHANGING ENVIRONMENTS WITH ANACONDA NAVIGATOR An
                environment is a directory that contains a specific
                collection of installed packages. These environments
                provide distinct workspaces, ensuring that packages
                within one environment remain independent and unaffected
                by those in another. This can reduce conflicts
                across  packages.  
              
                The base installation of Anaconda loads many packages.
                But we may want more. For example, for neural nets we
                may want to use the tensorflow module which is not part
                of the base installation. 
                The advice is to not add modules/packages to the base
                environment. 
                Instead create a new environment with the desired
                modules. 
                In Anaconda Navigator choose Environments. Then create.
                Then Search Packages but first do so for Uninstalled.
                Then find the desired uninstalled package and install. 
                To use the new environment go to Anaconda Navigator Home
                page and change base(root) to the new package.
                Note that if you are already using Spyder you will have
                to close Spyder and then reopen to switch to the new
                environment.
              See
https://docs.anaconda.com/free/navigator/tutorials/manage-environments/
            
For more on Python for regression: click
          here.
      
INSTALL ANACONDA FOR MAC
        WITH M1/M2 PROCESSOR
        
If you use a newer Mac with an M1/M2 processor then you should not install Anaconda using the default version which is for older intel CPU Macs. Instead install Anaconda using https://repo.anaconda.com/archive/Anaconda3-2023.03-MacOSX-arm64.pkg This installs the "arm64" version of Python. For Anaconda, go to the "Get Additional Installers" link from the homepage instead of just clicking on the download button.
If you do nonetheless install the Intel version you will get python to run, but in emulation mode. And you won't be able to use python within Stata. You have run into this problem if you get a message such as
dlopen(/Users/johndoe/anaconda3/lib/libpython3.10.dylib, 0x0009):
      tried: '/Users/johndoe/
      > anaconda3/lib/libpython3.10.dylib' (mach-o file, but is an
      incompatible architecture 
      > (have 'x86_64', need 'arm64')),
      '/System/Volumes/Preboot/Cryptexes/OS/Users/johndoe/an
      > aconda3/lib/libpython3.10.dylib' (no such file),
      '/Users/johndoe/anaconda3/lib/libpyth
      > on3.10.dylib' (mach-o file, but is an incompatible
      architecture (have 'x86_64', need 
      > 'arm64'))
      failed to load the shared library
      /Users/johndoe/anaconda3/lib/libpython3.10.dylib.
 
    A. Colin Cameron / UC-Davis Economics /  http://www.econ.ucdavis.edu/faculty/cameron